Solved

mysql joining table with itself

Posted on 2013-01-28
6
155 Views
Last Modified: 2013-01-29
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

0
Comment
Question by:sniger
6 Comments
 
LVL 21

Expert Comment

by:Tapan Pattanaik
ID: 38830022
SELECT a.*,  b.* FROM   'pages'  a
 left join  'pages'  b  on b.parent_id = a.id

WHERE a.parent_id = 1
0
 
LVL 8

Assisted Solution

by:guvera
guvera earned 250 total points
ID: 38830023
Hi,

Just remove the single code in pages and check it. Also look the below link. Hope it may helpful to you

http://stackoverflow.com/questions/4005643/mysql-left-join-one-table-to-itself
http://forums.mysql.com/read.php?10,224134,224140#msg-224140

Thanks
Guvera
0
 
LVL 21

Expert Comment

by:Tapan Pattanaik
ID: 38830028
SELECT a.*,  b.* FROM   'pages'  a
 left join  'pages'  b  on b.parent_id = a.id

WHERE b.parent_id = 1
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38830062
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

0
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 38830416
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

0
 
LVL 32

Accepted Solution

by:
awking00 earned 250 total points
ID: 38831522
You have 'pages` a with a leading quote and an ending back quote and 'pages' b with both a leading and ending quote.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question