9.5k views
0 votes
What does the following SQL query do? SELECT * FROM patient, disease, patient_disease;

User Loftx
by
7.5k points

1 Answer

3 votes

Final answer:

The SQL query performs a Cartesian product of the three tables 'patient', 'disease', and 'patient_disease', resulting in a large set that consists of all possible combinations of rows from these tables.

Step-by-step explanation:

The SQL query SELECT * FROM patient, disease, patient_disease; performs a Cartesian product or cross join of the three tables: patient, disease, and patient_disease. This means that for every row in the patient table, every row in the disease table is matched, and then for each of those combinations, every row in the patient_disease table is matched. The result is a large result set that contains all possible combinations of rows from the three tables, which could potentially be a very large number of rows.

Usually, a where clause would specify how these tables relate to each other, but in this case, without any where clause or join condition, the query does not filter any rows out. It is generally not advisable to perform a query like this without proper join conditions unless there is a very specific reason for wanting a Cartesian product, as it is rare to need every possible combination of rows and can be costly in terms of performance.

User Cphlewis
by
8.0k points