Jump to content

Recommended Posts

Alrighty so I was finally convinced to use JOIN instead of implicitly joining in the where clause.  However, I'm unable to properly construct the queries for some of my more complex stuff.

 

For this one I am dealing with three tables.  Using the whole tables here would just over complicate the situation so I simplified the definitions to only what is relevant here.  A node can be associated with zero or many platform.  A platform can have zero or many nodes.  I don't care about nodes without platforms or platforms without nodes (either of these cases is someone else's problem).

 

Table 1: node (simplified)

id, hostname, tier

 

Table 2: platform (simplified)

id, platname

 

Table 3 node_platform

node, platform

 

Without JOIN:

SELECT tier, hostname, platname
FROM node, platform, node_platform
WHERE node_platform.node = node.id
  AND node_platform.platform = platform.id

 

 

How would this be written using JOIN?

Link to comment
https://forums.phpfreaks.com/topic/95455-complex-for-me-join/
Share on other sites

Could you give an example of what you mean by

I like to prefix field names and alias tables.

 

SELECT tier, hostname, platname
FROM node AS n
INNER JOIN node_platform AS np ON np.node = n.id
INNER JOIN platform AS p ON p.id = np.platform

Same for the fields, but I don't know which tables they're in.

Link to comment
https://forums.phpfreaks.com/topic/95455-complex-for-me-join/#findComment-488786
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.