I have 3 MySQL tables called ‘orders’, ‘orders_queue’ and ‘orders_sent’. The order number is primary key for all these tables, for orders table it’s called “num”, for orders_queue it’s “ordernum” and for orders_sent it’s “order_id”.
Clause: List max 10 order numbers sorted by Rand() that exist in table ‘orders’ but do not exist in ‘orders_queue’ nor in ‘orders_sent’ OR if it exists in ‘orders_sent’, these lines have also a field called ‘foo’ set to ‘’.
SELECT orders.num
FROM orders
WHERE NOT EXISTS
( SELECT 'curly'
FROM orders_queue
WHERE ordernum = orders.num )
AND NOT EXISTS
( SELECT 'larry'
FROM orders_sent
WHERE order_id = orders.num )
AND NOT EXISTS
( SELECT 'moe'
FROM orders_sent
WHERE order_id = orders.num
AND foo <> '' )
That isn’t what you suggested in your earlier post. If you can show the information you can be helped with it. Without the information we can’t guess at what the difficulty is.