New answers tagged

1

Test: SELECT CASE WHEN sender_id = 1 THEN receiver_id ELSE sender_id END user_id FROM messages WHERE 1 IN (sender_id, receiver_id) GROUP BY user_id ORDER BY MAX(id) DESC LIMIT 3


-1

You can also try with sub query SELECT * FROM comments WHERE user_id in ( Select id from data where id = ? )


0

Get a suitably large random number (eg 6 digits of RAND()), then double check against your existing table to see if that number is already taken. If so, try again. If you want letters and digits, that can be achieved using BASE64(): SELECT MID(TO_BASE64(RAND()), 6,6); +-----------------------------+ | MID(TO_BASE64(RAND()), 6,6) | +------------------------...


Top 50 recent answers are included