×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

query where statement two row in same column

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

RE: query where statement two row in same column

OR

"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

(OP)
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  

RE: query where statement two row in same column

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"

RE: query where statement two row in same column

(OP)
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

RE: query where statement two row in same column

You need to clearly define what you're trying to do.

-- Jason
"It's Just Ones and Zeros"

RE: query where statement two row in same column

Did you try my suggestion ?

RE: query where statement two row in same column

(OP)
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.  

RE: query where statement two row in same column

(OP)
phv: yup, try already, but not quit work for the table i newly create the desease id = 4...  

RE: query where statement two row in same column

perharps you mean to say

select * from table where column sy_id = $val  ?

RE: query where statement two row in same column

No way to edit posts here !

select * from table where sy_id = $val  ?

RE: query where statement two row in same column

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close