Angular_Newbie Angular_Newbie - 6 months ago 10
SQL Question

How to convert old SQL?

I am converting deprecated SQL (*=) to Left Join. Are the following SQL statements equivalent? Will performance be improved?

OLD

SELECT n.name,
n.address,
e.email,
e.title,
m.car,
l.type
FROM name n,
employee e,
miscellaneous m,
lifestyle l
WHERE n.id = 3
AND n.id = e.id
AND n.id *= m.id
AND n.id *= l.id;


NEW

SELECT n.name,
n.address,
e.email,
e.title,
m.car,
l.type
FROM name n,
employee e,
miscellaneous m,
lifestyle l
Inner Join empId ON n.id = e.id
Left Join miscId ON n.id = m.id
Left Join lifeId ON n.id = l.id;

Answer

You new query isn't correct.

The converted version will be

SELECT n.NAME
    , n.address
    , e.email
    , e.title
    , m.car
    , l.type
FROM NAME n
INNER JOIN employee e ON n.id = e.id
LEFT JOIN miscellaneous m ON n.id = m.id
LEFT JOIN lifestyle l ON n.id = l.id;

WHERE n.id = 3

Both queries will perform the same. The first one is just old style.

Please "Mark as Answer" if a post has answered the question

Comments