Link to home
Start Free TrialLog in
Avatar of motioneye
motioneyeFlag for Singapore

asked on

sql query

Hi,
How do I query a single table with two column in where clause  for a multiple values ? I have a value with me in where cluse but not sure how to put this in construct query


The where clause must be a combination of two column within a table , the query below works with only per row ouput, but how I have this for multiple value ?

select * from VemployeeDisc  where [AD Domain] ='AAPAC' and [ADACCTName]='EMMKZY'

[AD Domain]      [ADACCTName]
AAPAC           EMMKZY
AMERICAS        EMMZZZ
AAPACII         EMMZARO
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

try use OR:

select * from VemployeeDisc  where [AD Domain] ='AAPAC'  OR [ADACCTName]='EMMKZY'

or:

select * from VemployeeDisc  where [AD Domain] in ('AAPAC','EMMKZY')  OR [ADACCTName] in ('AAPAC','EMMKZY')

?
AND Return value if both AD Domain and ADACCTName satisfy,
If you want to return any of them you can use OR,IN,Between functions as per Ryan Chong solution.
SOLUTION
Avatar of gplana
gplana
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of motioneye

ASKER

Hi,
Actually in the table it self we have multiple values as below and the problems is I need to select maybe around 20-30 records  for an ad-hoc request from user

[AD Domain]      [ADACCTName]
AAPAC           EMMKZY
AMERICAS        EMMZZZ
AAPACII         EMMZARO
AAPACII                 EMMZZZ
AMERICAS              EMMKZY
AAPACII         EMMZARO
if you are comparing similar values in a field, you probably can use Like clause instead.

for example:

select * from VemployeeDisc  where [AD Domain] like '%AAPAC%'  OR [ADACCTName] like '%EMM%'

for more info:
https://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
motioneye, do you still need help with this question?