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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.