MySQL Join Multiple Tables

I have three tables:

t1.estimate, t1.mid, t1.description, t1.status t2.mid, t2.mname, t2.mphone, t2.memail t3.estimate, t3.action 

I need to join these tables, but the problem I ran into is that t2 and t3 may not contain entries for joining t1. Table t1 is the main table in which the filter will be applied. Table t2 will in 99.9% of cases contain a match when combining 'mid'. But table t3 is a table in which only information is stored and an estimate is created when the user enters it into the table. At t1 there can be 40,000 plus entries, but only 5,000 at t3.

Here is my current code, but it only displays the records that are in all three tables. I would like the values ​​to be displayed from t1, even if there are no entries to attach to t2 and t3.

 SELECT DISTINCT t1.estimate, t1.mid, t2.mname, t1.description, t1.status, GROUP_CONCAT(t3.action) FROM t1 LEFT OUTER JOIN t2 ON t1.mid = t2.mid LEFT OUTER JOIN t3 ON t1.estimate = t3.estimate WHERE t1.status LIKE '0%' GROUP BY t3.estimate 
+4
source share
1 answer

You need to change GROUP BY to use t1.estimate instead of t3.estimate , since t3.estimate will be NULL if no entries are merged.

+3
source

All Articles