views:

61

answers:

2

Hi,

I have a table with three columns and I have fetch a column whose value matches with value 'aaaa' and 'bbbb'

columnA         ColumnB        ColumnC
 data1           yyyy           aaaa
 data2           zzzz           mmmm
 data1           hhhh           nnnn
 data3           aaaa           bbbb

So, if I query with "Select * from above.table where ColumnA = 'aaaa' and ColumnA = 'bbbb';" I get the answer as 'no rows selected'!!!. Am I going committing an error?

Thanks,

+2  A: 

That's because a column can not be two values at the same time--you need to use an OR:

SELECT *
  FROM YOUR_TABLE
 WHERE (columnc = 'aaaa'
    OR columnc = 'bbbb')

An alternative syntax is the IN clause:

SELECT *
  FROM YOUR_TABLE
 WHERE columnc IN ('aaaa','bbbb')
OMG Ponies
+2  A: 

Think about it for a minute. You're performing an AND operation expecting one column to match two different values (X=1 AND X=2). It can never happen logically. I suspect you want an OR instead.

select *
    from YourTable
    where ColumnA = 'aaaa' OR ColumnA = 'bbbb'
Joe Stefanelli