Jump to content

[SOLVED] MYSQL JOINS


aclab

Recommended Posts

Hi, my understanding of different mysql joins is quite limited, I have two statements below which I'm assuming can be combined into one but I'm not sure how to approach it:

 

$sql = "SELECT * FROM galleries WHERE id = '" . $id . "'";

$data = mysql_query($sql);

$sql = "SELECT title FROM galleries WHERE id = '" . $data[parentID] . "'";

 

The 'galleries' table holds both the child and parent galleries, so in the above I'm looking to get all the fields for the child gallery in question, and then the title of the parent gallery from the same table.

 

On the same note if anyone knows of any good resources/tutorials for mysql joins (preferrably rich in examples!)...

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/159568-solved-mysql-joins/
Share on other sites

  • 2 weeks later...

Ahh... realised while implementing that I made an error in my description and thus the solution provided... all fields should ALWAYS be retrieved for the requested record, whereas the parentID should only be retrieved IF IT EXISTS. The above statement will only return a record if a parentID exists. Any further advice for adapting this statement?

Link to comment
https://forums.phpfreaks.com/topic/159568-solved-mysql-joins/#findComment-848655
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.