Answer the question
In order to leave comments, you need to log in
Is it possible to get information about the existence of a record in another table in a SELECT query to one table?
I make a request , can I somehow display the same request if there is a record with id = 1 in table2?
I found this code, but I don't know how to combine it all.select * from table1 where id = 1
SELECT EXISTS(SELECT id FROM table2 WHERE id = 1)
Answer the question
In order to leave comments, you need to log in
select table1.*, IF(table2.id IS NULL, 0, 1) as existsInTable2 from table1
left join table2 on table2.id = table1.id
where table1.id = 1
This is some kind of nonsense.
First, you should never try to cram all queries into one database call.
If the tables are not related to each other in any way, then you just need to make two queries.
Secondly, the question itself speaks of the crooked structure of the tables. The unique identifiers of one table have nothing to do with the unique identifiers of another.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question