Answer the question
In order to leave comments, you need to log in
How to write an additional field is_x in SQL if the row id from this table is in another table?
Please tell me how can I write a SQL query so that a "dynamic" field is added to the current table, which will be true if the row ID is in another query, false if it is not there.
Example:
article -> popular
article.is_popular if exists in SELECT * FROM `articles` WHERE `views` > 10000
something like this
Answer the question
In order to leave comments, you need to log in
Issue resolved.
SELECT *, CASE
WHEN EXISTS (SELECT * FROM `articles` as trends WHERE `views` > 10000 AND WHERE trends.`id` = `articles`.id)
THEN 1
ELSE 0
END AS is_popular
FROM `articles`
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question