Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query where statement two row in same column

Status
Not open for further replies.

yoyok007

Programmer
Feb 21, 2009
5
MY
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
 
OR

"select dm_id from desease_details where sy_id = $val OR sy_id = $val2"



-- Jason
"It's Just Ones and Zeros
 
below are my sample table

-------------------------
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
 
I do understand what you're asking for which is why based on the info provided I said to use OR.... change the AND in your query to OR.

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
 
What about something like this ?
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
FAQ181-2886
 
thanks for reply guys, but the table dont actually like above,for some case, it can be like below

-------------------------
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
 
You need to clearly define what you're trying to do.

-- Jason
"It's Just Ones and Zeros
 
the situation is like this, this is for desease detection, to make it simple, there are 2 table which are symptom and desease.

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.
 
phv: yup, try already, but not quit work for the table i newly create the desease id = 4...
 
perharps you mean to say

select * from table where column sy_id = $val ?
 
No way to edit posts here !

select * from table where sy_id = $val ?
 
you need to use intersect

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top