query where statement two row in same column
query where statement two row in same column
(OP)
my query is
"select dm_id from desease_details where sy_id = $val and sy_id = $val2"
this query sure not working, anyone have idea how i can solve this?
thnx
"select dm_id from desease_details where sy_id = $val and sy_id = $val2"
this query sure not working, anyone have idea how i can solve this?
thnx
RE: query where statement two row in same column
"select dm_id from desease_details where sy_id = $val OR sy_id = $val2"
-- Jason
"It's Just Ones and Zeros"
RE: query where statement two row in same column
-------------------------
id(pk) | sy_id | dm_id
-------------------------
1 | 1 | 1
2 | 2 | 1
3 | 1 | 2
4 | 4 | 3
--------------------------
as my first post "select * from table where sy_id = 1 and sy_id = 2"
because i want to get the row for column dm_id = 1
hope you guys understand my explaination. thnx again
RE: query where statement two row in same column
select * from table where sy_id = 1 OR sy_id = 2
But given this new info it shows tha using OR will give you the 2 rows you seek plus an additional row.
But note -- your AND condition will never work. The sy_id cannot be 1 AND 2 (in the same row).
So....to get the 2 rows you see AND ONLY the 2 rows you seek you will need to add additional criteria to your select.
Like this....
select * from table where sy_id = 1 OR sy_id = 2 and dm_id <> 2
or
select * from table where dm_id = 1
-- Jason
"It's Just Ones and Zeros"
RE: query where statement two row in same column
SELECT dm_id
FROM desease_details
WHERE sy_id = $val OR sy_id = $val2
GROUP BY dm_id
HAVING COUNT(*) = 2
Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?
RE: query where statement two row in same column
-------------------------
id(pk) | sy_id | dm_id
-------------------------
1 | 1 | 1
2 | 2 | 1
3 | 1 | 2
4 | 4 | 3
5 | 1 | 4
6 | 3 | 4
7 | 4 | 4
--------------------------
if you can see, the desease dm_id=4 has 3 symptom sy_id, 1,3,4
ya, i know to use AND is imposibble, and i think for OR also not kinda work out dude
any suggest? really appreciate it guys
RE: query where statement two row in same column
-- Jason
"It's Just Ones and Zeros"
RE: query where statement two row in same column
RE: query where statement two row in same column
The desease are determine by its symptom and 1 desease may have 1 or more symptom.
the table above is for the desease table, sy_id is for symptom id(fk from symptom table) and dm_id is for desease master id (fk from desease master table)
to use the system, user will only choose the symptom (checkbox) then send the value to db.
RE: query where statement two row in same column
RE: query where statement two row in same column
select * from table where column sy_id = $val ?
RE: query where statement two row in same column
select * from table where sy_id = $val ?
RE: query where statement two row in same column
select dm_id from table where sy_id = 1
intersect
select dm_id from table where sy_id = 2
will return only the dm_id value = 1