Jump to content

Query Select All Except 1


hackerkts

Recommended Posts

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 ?
Link to comment
https://forums.phpfreaks.com/topic/13196-query-select-all-except-1/
Share on other sites

...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--]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.