hackerkts Posted June 29, 2006 Share Posted June 29, 2006 Hey it's me again. [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /] Anyone know how to do a sql query which select all except one, if I'm not wrong it has some like "NOT".But I couldn't get it right, think I didn't get the query working.[code]$query = "SELECT * FROM table";$result = mysql_query($query) or die("Query failed: " . mysql_error());while($row = mysql_fetch_assoc($result)) {}[/code]Thanks again [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /][b]Edit[/b]: Ops, sorry to tell, I doesn't want it to echo out id 1.Table structure: id, date and content.[b]Edit2[/b]: Ops lolz, just a few second after I post. An idea just flash through my mind.[code]$query = "SELECT * FROM table";$result = mysql_query($query) or die("Query failed: " . mysql_error());while($row = mysql_fetch_assoc($result)) {if ($row['id'] == 1) {} else {}}[/code]But I know it's not the best way, so anyone know how to do in other way ? Quote Link to comment https://forums.phpfreaks.com/topic/13196-query-select-all-except-1/ Share on other sites More sharing options...
hvle Posted June 29, 2006 Share Posted June 29, 2006 ok, so you do not want to include id 1 into your result:simple.$query = "SELECT * FROM table where id != 1"; Quote Link to comment https://forums.phpfreaks.com/topic/13196-query-select-all-except-1/#findComment-50785 Share on other sites More sharing options...
obsidian Posted June 29, 2006 Share Posted June 29, 2006 ...or, if you end up having more than one restriction you want to filter out, just use NOT IN:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * [color=green]FROM[/color] [color=orange]tableName[/color] [color=green]WHERE[/color] id NOT [color=green]IN[/color] ([color=red]'1'[/color], [color=red]'2'[/color], [color=red]'3'[/color]);[!--sql2--][/div][!--sql3--] Quote Link to comment https://forums.phpfreaks.com/topic/13196-query-select-all-except-1/#findComment-50792 Share on other sites More sharing options...
hackerkts Posted June 29, 2006 Author Share Posted June 29, 2006 Thanks hvle & obsidian, oh.. So I forgotten the "IN" :sThanks again :D*staring at the title "Super Guru" :P* Quote Link to comment https://forums.phpfreaks.com/topic/13196-query-select-all-except-1/#findComment-50850 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.