Re: [PHP-DB] SQL omit record if ever had value set
On Mon, Jun 18, 2012 at 6:26 PM, Matijn Woudt wrote: > On Mon, Jun 18, 2012 at 11:56 PM, Dee Ayy wrote: >> I would like a query that lists records where a column has not taken >> on a specific value when grouped by another column. >> >> N V >> n1 v1 >> n1 v2 >> n2 v1 >> n2 v2 >> n2 v3 >> n3 v1 >> >> If v3 has ever been set for N, do not list N. So the result would be n1, n3 >> >> If v2 has ever been set for N, do not list N. So the result would be only n3 >> >> MSSQL >> >> TIA >> > > I guess this should work in MSSQL too: > > SELECT N FROM table WHERE N NOT IN (SELECT N FROM table WHERE v = v3) > > - Matijn Thank you. So simple. I must have had Monday afternoon burnout. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] SQL omit record if ever had value set
On Mon, Jun 18, 2012 at 11:56 PM, Dee Ayy wrote: > I would like a query that lists records where a column has not taken > on a specific value when grouped by another column. > > N V > n1 v1 > n1 v2 > n2 v1 > n2 v2 > n2 v3 > n3 v1 > > If v3 has ever been set for N, do not list N. So the result would be n1, n3 > > If v2 has ever been set for N, do not list N. So the result would be only n3 > > MSSQL > > TIA > I guess this should work in MSSQL too: SELECT N FROM table WHERE N NOT IN (SELECT N FROM table WHERE v = v3) - Matijn -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] SQL omit record if ever had value set
I would like a query that lists records where a column has not taken on a specific value when grouped by another column. N V n1 v1 n1 v2 n2 v1 n2 v2 n2 v3 n3 v1 If v3 has ever been set for N, do not list N. So the result would be n1, n3 If v2 has ever been set for N, do not list N. So the result would be only n3 MSSQL TIA -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php