Link to home
Start Free TrialLog in
Avatar of sniger
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

Open in new window

Avatar of Tapan Pattanaik
Tapan Pattanaik
Flag of India image

SELECT a.*,  b.* FROM   'pages'  a
 left join  'pages'  b  on b.parent_id = a.id

WHERE a.parent_id = 1
SOLUTION
Avatar of guvera
guvera
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SELECT a.*,  b.* FROM   'pages'  a
 left join  'pages'  b  on b.parent_id = a.id

WHERE b.parent_id = 1
Avatar of Robert Schutt
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

Open in new window

try this
SELECT a.*,  b.* 
FROM   pages a left join  pages  b  
on (b.parent_id = a.id)  
WHERE a.parent_id = 1

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial