Jump to content

Complex (for me) Join


fnairb

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

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.