Jump to content
MakeWebGames

MYSQL - JOINS in querys help!


Recommended Posts

Hello there would be greatful if someone could help me with a problem I am having. Basically I want to create a query which selects from three tables in my database, I know this query uses the JOIN and I have a basic knowladge of what it should look like but I am not 100% sure how to do it.

I know it should be something along the lines of:

$dd = $db->query("SELECT * FROM `table1` JOIN `table2` ON `table1.id` = `table2.id` JOIN `table3` ON `table2.id` = `table3.id` WHERE `table1.id` = 1");

 

I think....

Table 1 should be- `dogs`

Table 2 should be- `dogs_stats`

Table 3 should be- `dogs_bgc`

But I am unsure what to put in `table1.id`,`table2.id` and `table3.id`

If someone could point me in the right direction that would be great.

Link to comment
Share on other sites

You would need to have an identifier that is the same across all tables.

For example ... users.userid to userstats.userid to inventory.inv_userid.

That kind of thing.

To clarify that just a little bit, the column names don't have to be the same. They just have to hold the same values.

Link to comment
Share on other sites

So I need to create a common value in each table? Something like `dog_id`? Which would make the query:

$dd = $db->query("SELECT * FROM `dogs` JOIN `dogs_stats` ON `dogs.dog_id` = `dogs_stats.dog_id` JOIN `dogs_bgc` ON `` = `dogs_bgc.dog_id` WHERE `dogs.dog_id` = 1");

 

Would that be correct?

Link to comment
Share on other sites

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.   Paste as plain text instead

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