Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
join1_databaser [2016-10-28 13:07]
Joakim Forsgren
join1_databaser [2018-10-05 14:33]
Joakim Forsgren
Line 1: Line 1:
 ====== Databaser + enkla JOIN ====== ====== Databaser + enkla JOIN ======
 +<code sql>
 +# Eventuellt måste man köra detta kommando för att få GROUP BY att fungera.
 +# Får ni felet ...incompatible with sql_mode=only_full_group_by... kör kommandot nedan
 +SET sql_mode=(SELECT REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY', ''));
 +</code>
 Gå igenom ''inner join'', ''left/right join'', ''group by'', ''count'', ''sub select'' och ''having'' Gå igenom ''inner join'', ''left/right join'', ''group by'', ''count'', ''sub select'' och ''having''
-<code> +<code type=mysql> 
-select join_users.*, join_items.date, count(join_items.user_id) as antal from join_users left join join_items on join_users.user_id=join_items.user_id where join_users.user_id > 25 group by join_users.user_id having antal=0 order by antal desc;+# ex från genomgång 
 +select join_users.*, join_items.date, count(join_items.user_id) as antal  
 +from join_users  
 +left join join_items  
 +on join_users.user_id=join_items.user_id  
 +where join_users.user_id > 25  
 +group by join_users.user_id  
 +having antal=0  
 +order by antal desc;
 </code> </code>