Retrieving data from a database and filtering results

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.

SELECT * FROM notification WHERE toUserId = 'email' ORDER BY id DESC LIMIT 50;
+3
source share
3 answers

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.

+4
source

50 IsRead, , , Sql.

SELECT * FROM (SELECT TOP 50 * FROM notification) S WHERE toUserId = 'email' and isread=false

. MySql.

+1
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 ( ), . .

0

All Articles