Solved

mysql joining table with itself

Posted on 2013-01-28
6
153 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
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.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 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