Solved

mysql joining table with itself

Posted on 2013-01-28
6
157 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

 
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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

'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 …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

630 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