In mysql database, I have two tables A
and B
and would like to select
A
if table B
has any rowsA
if table B
has no recordsHow should I write my SQL query?
Table A
and B
have columns id
and name
.
Just check in the where-condition, if b
has any rows:
SELECT a.*
FROM a
WHERE EXISTS(SELECT 1 FROM b);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.