Mysql – Joins

Create a temporary table

LEFT JOIN (Select cuisine_styles_assign.content_id, GROUP_CONCAT(IF(cuisine_styles.name IS NOT NULL, CONCAT(cuisine_styles.name, "-",cuisine_styles.id), CONCAT(countries.nationality, "-",cuisine_styles.id, "-", countries.country_code_alpha2)) SEPARATOR ";") as cuisine_styles from cuisine_styles_assign LEFT JOIN cuisine_styles ON cuisine_styles.id = cuisine_styles_assign.cuisine_styles_id LEFT JOIN countries ON countries.id = cuisine_styles.countries_id where cuisine_styles_assign.disabled IS NULL AND assign_types_id = 1 GROUP BY content_id) as yjiyymuy ON  yjiyymuy.content_id = items.id

“yjiyymuy” is the name of the temp table

How “FROM” and joins are connected

When writing “FROM”, joins pertaining to a table need to be written immediately after the table is writen

FROM ratings, items INNER JOIN files ON files.id = items.files_id

this is correct

FROM itemsm, ratings INNER JOIN files ON files.id = items.files_id

this is’nt

LEFT OUTER JOIN

if you have a situation where a join your making is based on a NULL value

in this case, maybe no rating was left on item, so in this case it should result in a column being null.

Leave a Reply

Your email address will not be published.