c7borg Posted May 29, 2014 Share Posted May 29, 2014 Hi all.. My head just isn't working correctly today I can write this in english but can't think how to put this or even search for the code I'm looking for.. so I have a table such as this.. id - lineno - hitcount1 - 2 - 02 - 2 - 03 - 3 - 04 - 3 - 15 - 4 - 06 - 4 - 07 - 4 - 0 And want to echo only if the hitcount is 0 for everything with a lineno of x So in this case I should return lines 1,2,5,6 & 7 but not 3. Any help appreciated Andy. Quote Link to comment https://forums.phpfreaks.com/topic/288856-if-statment-or-mysql-query-im-not-sure/ Share on other sites More sharing options...
Ch0cu3r Posted May 29, 2014 Share Posted May 29, 2014 That can be handled by your query, example SELECT id, lineno FROM table WHERE hitcount = 0 The above query will return all records with a hitcount of 0 If you want all records where lineno is not 3 and has a hit count of 0 you'd use SELECT id, lineno FROM table WHERE lineno != 3 && hitcount = 0 Quote Link to comment https://forums.phpfreaks.com/topic/288856-if-statment-or-mysql-query-im-not-sure/#findComment-1481257 Share on other sites More sharing options...
Psycho Posted May 29, 2014 Share Posted May 29, 2014 (edited) @Chocu3r, I think he only only wants records where ALL records for each unique lineno ID have a hitcount of 0. In his example above there are two records with a lineno of 3. But, one of them has a value that is not 0. Therefore, all records with a lineno of 3 should be excluded. @c7borg: Use a subquery to select the lineno's which have a non-zero value. Use that result to then select all records that do not use those lineno values. SELECT id, lineno FROM table_name WHERE lineno NOT IN (SELECT DISTINCT lineno FROM table_name WHERE hitcount <> 0) Edited May 29, 2014 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/288856-if-statment-or-mysql-query-im-not-sure/#findComment-1481289 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.