Answer the question
In order to leave comments, you need to log in
How to generate a sql query to select from two tables?
There are two tables:
1. id|title|description
2. id|id_iz_pervoi_tablici|flag
Help us form a sql query that will return rows from the first table, only those whose flag in the second buffer is 0.
id = id_iz_pervoi_tablici. It is highly desirable that this be one sql query
Answer the question
In order to leave comments, you need to log in
For MySQL 8.0:
Faster option (but it's not accurate):
SELECT * FROM `t1` WHERE EXISTS (SELECT * FROM `t2` WHERE `t1`.`id` = `t2`.`id_iz_pervoi_tablici` AND `flag`=0)
SELECT * FROM `t1`
LEFT JOIN (SELECT * FROM `t2` WHERE `flag`=0) AS `t2`
ON `t1`.`id` = `t2`. `id_iz_pervoi_tablici`
SELECT t1.*
FROM t1
JOIN t2 ON t2.id_iz_pervoi_tablici = t1.id
WHERE t2.flag = 0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question