tags:

views:

46

answers:

2

Hi,

I have something like this

select A, B, C
from tableA
where A = '123'
group by B

and the results include entries whose A is not '123'. Why is this not the results I expected it to be?

thanks

database has 16k entries

actual result (7k entries): a mixture of entries with A='123' and A='other'

expected results (5k entries): all entries with A='123'

+1  A: 

Your query will not work as A and C are not inside group by condition. For C you have to use Min, Max, Avg, Count,... aggregate functions, while for A you can use either aggregate function or diretly value of A something like:

Select Max(A) as A, B, Max(C) as C 
From Table
Where A='123'
Group by B

Or

Select '123' as A, B, Max(C) as C 
From Table
Where A='123'
Group by B
Niikola
or you can group by A,B
Michał Piaskowski
A: 

try this

select A, B, C from tableA

group by B having A="123" or

select A from tableA

group by B having A="123"

Thanks

Shakti Singh