Solved

mysql joining table with itself

Posted on 2013-01-28
6
151 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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 31

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now