SQL 1:
SELECT
a.*,
b.name
FROM
t_coach a
LEFT JOIN t_school b on a.school_id=b.id
SQL 2:
SELECT a.*, (select b.name FROM t_school b WHERE b.id= a.school_id) AS name FROM t_coach a
SQL1 and SQL2 get the same result.
Can the second SQL be written like this in actual development?
Compared with SQL1, is SQL2 less efficient?
phpcn_u15822017-05-18 10:46:43
SQL1, table B is only scanned once
SQL2, table B will be scanned as many times as there are records in table A
When the amount of data in your database is enough, SQL2 will not be able to produce results directly, and will kill the database