sniger
asked on
mysql joining table with itself
Hi , what is wrong with this syntax:
SELECT a.*, b.* FROM 'pages` a
left join 'pages' b on (b.parent_id = a.id)
WHERE a.parent_id = 1
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SELECT a.*, b.* FROM 'pages' a
left join 'pages' b on b.parent_id = a.id
WHERE b.parent_id = 1
left join 'pages' b on b.parent_id = a.id
WHERE b.parent_id = 1
Use backticks consistently to quote table names or leave them out altogether.
SELECT a.*, b.* FROM `pages` a
left join `pages` b on (b.parent_id = a.id)
WHERE a.parent_id = 1
try this
SELECT a.*, b.*
FROM pages a left join pages b
on (b.parent_id = a.id)
WHERE a.parent_id = 1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
left join 'pages' b on b.parent_id = a.id
WHERE a.parent_id = 1