I get the first 50 entries using this query. However, in the same table there is a flag with a name read, and I want to return only the first 50 records that are not read(i.e. isread=false). How can i achieve this? Can someone give me ideas for the requested request? I tried using subqueries.
read
isread=false
SELECT * FROM notification WHERE toUserId = 'email' ORDER BY id DESC LIMIT 50;
Try to add a condition ANDto your suggestion of the WHERE: userID = 'email' AND flag = true. This will only return users with the true value for the flag, from which you can get the 50 best in their ultimate state.
AND
userID = 'email' AND flag = true
50 IsRead, , , Sql.
SELECT * FROM (SELECT TOP 50 * FROM notification) S WHERE toUserId = 'email' and isread=false
. MySql.
SELECT * FROM notification WHERE toUserId = 'email' AND isread = 0 ORDER BY id DESC LIMIT 50;
, , 0 false 1 ( - ) true. tinyint BOOL, ( , tinyint -9 +9, , 0 1 .
-, , 1 0, TRUE FALSE ( ), . .