Question

An input form was designed for me that stores the information in 4 different tables in one database. I now need to recombine these back into one.

The primary table is Paintings

All variable fields actual data is stored in Medium_options

The PID in Paintings and MOID in Medium_options are linked together in Painting_medium

My goal is to write a SELECT statement to combine this data into one $sql statement:

Here is an example of what I have and need.

Any help would be greatly appreciated.

Was it helpful?

Solution

Try this, changing the * to the columns you require (p.size, m.medium_name etc):

SELECT  *  
FROM    paintings AS p  
        INNER JOIN painting_medium AS pm  
            ON p.pid = pm.pid  
        INNER JOIN medium_options mo  
            ON pm.moid = mo.moid
        INNER JOIN medium m
            ON mo.medium_id = m.medium_id

So your first line would be along the lines of:

SELECT  p.category AS Category
       ,mo.medium_option AS Size
       ,m.medium_name AS Material
FROM   paintings AS p  
etc
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top