postgres counting one record twice if it meets certain criteria
Posted
by Dashiell0415
on Stack Overflow
See other posts from Stack Overflow
or by Dashiell0415
Published on 2010-05-30T15:50:11Z
Indexed on
2010/05/30
15:52 UTC
Read the original article
Hit count: 310
I thought that the query below would naturally do what I explain, but apparently not...
My table looks like this:
id | name | g | partner | g2
1 | John | M | Sam | M
2 | Devon | M | Mike | M
3 | Kurt | M | Susan | F
4 | Stacy | F | Bob | M
5 | Rosa | F | Rita | F
I'm trying to get the id where either the g or g2 value equals 'M'... But, a record where both the g and g2 values are 'M' should return two lines, not 1.
So, in the above sample data, I'm trying to return:
$q = pg_query("SELECT id FROM mytable WHERE ( g = 'M' OR g2 = 'M' )");
1
1
2
2
3
4
But, it always returns:
1
2
3
4
© Stack Overflow or respective owner