checking if records exists in DB, in single step or 2 steps?
- by Sinan
Suppose you want to get a record from database which returns a large data and requires multiple joins.
So my question would be is it better to use a single query to check if data exists and get the result if it exists. Or do a more simple query to check if data exists then id record exists, query once again to get the result knowing that it exists.
Example:
3 tables a, b and ab(junction table)
select * from from a, b, ab where condition and condition and condition and condition etc...
or
select id from a, b ab where condition
then if exists do the query above.
So I don't know if there is any reason to do the second. Any ideas how this affects DB performance or does it matter at all?