mysql multiple joins code example

Example 1: multiple joins mysql

SELECT dashboard_data.headline, dashboard_data.message, dashboard_messages.image_id, images.filename
FROM dashboard_data 
    INNER JOIN dashboard_messages 
        ON dashboard_message_id = dashboard_messages.id
    INNER JOIN images
        ON dashboard_messages.image_id = images.image_id

Example 2: mysql two joins

SELECT areas.name AS aname, COUNT(consultants.active) AS cct 
    FROM areas 
    LEFT JOIN consAreas 
      ON consAreas.area = areas.id 
    LEFT JOIN consultants 
      ON consultants.id = consAreas.cons
   WHERE areas.areaID = $area 
     AND consultants.active = 1
GROUP BY areas.name
ORDER BY areas.name

Example 3: How to use multiple join in mysql

SELECT 
    t1.name name,
    t1.id id,
    t1.add_date add_date, 
    t2.soc_township township_name1,
    t2.soc_name soc_name,
    t3.name township_name
FROM block t1 
INNER JOIN society t2
    ON (t1.soc_id = t2.id)
INNER JOIN township t3
    ON (t2.soc_township = t3.id)

Tags:

Sql Example