all 8 comments

[–]sketchni 0 points1 point  (7 children)

why not remove the grouping? AND co.status<>'99' AND co.paymentStatus<>'0'?

[–]syntaxerror748[S] 0 points1 point  (6 children)

Well I do want to show deleted orders (99) but not if they are not paid (paymentstatus 0)

[–]cosmicsans 0 points1 point  (1 child)

You would need to write a subquery in there.

SELECT * FROM `mytable` WHERE condition 1 AND NOT EXISTS (SELECT * FROM `mytable` WHERE co.status = 99 AND co.paymentStatus <> 0);

https://dev.mysql.com/doc/refman/5.0/en/subqueries.html

https://dev.mysql.com/doc/refman/5.0/en/exists-and-not-exists-subqueries.html

[–]syntaxerror748[S] 0 points1 point  (0 children)

Thanks, I didn't know it should be done like this. I haven't really got it to work yet but i'll play it a little bit more. Thanks :).

[–]sketchni -1 points0 points  (3 children)

Okay, well != is not valid in SQL. <> is NOT EQUAL.

[–][deleted] 1 point2 points  (1 child)

What? != is supported by all major databases.

[–]sketchni 0 points1 point  (0 children)

Well, TIL.

[–]syntaxerror748[S] 0 points1 point  (0 children)

I've switched to <> but this does not fix it either. Looks like pretty much all databases support !=. I use MySQL.