I have two relational tables.
item_id int(11)
staff_id int(11)
item_id int(11)
entry_id int(11)
I want to check if an item_id does not exist in both tables.
like this:
SELECT EXISTS ( SELECT * FROM staffs_items AS si WHERE si.item_id = 1 ) AS exist;
+-------+
| exist |
+-------+
| 1 |
+-------+
SELECT EXISTS ( SELECT * FROM entries_items AS ei WHERE ei.item_id = 1 ) AS exist;
+-------+
| exist |
+-------+
| 0 |
+-------+
I want to run those queries in a one liner.
If item_id does not exist in either table, I want to return 0 (false).
How can I do that?
You could just place both exists subqueries into a single select:
SELECT
EXISTS (SELECT 1 FROM staffs_items WHERE item_id = 1) AS exists_staff_item,
EXISTS (SELECT 1 FROM entries_items WHERE item_id = 1) AS exists_entries_item;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments