Mysql 6: JOIN
Written by: maffelu , 2009-04-16 21:19:21
|--------------------+--------------------+--------------------|
|store_name |store_sales |store_updates |
|____________________+____________________+____________________|
|Hanks Hardware 2500 2009-01-01 00:00:00 |
|Santos SuperStore 750 2008-12-01 00:00:00 |
|Bobs Boutique 1250 2009-01-01 00:00:00 |
|Pattyïs Pantstore 1050 2008-12-15 00:00:00 |
|Hanks Hardware 2250 2008-01-01 00:00:00 |
+--------------------------------------------------------------+
|--------------------+--------------------|
|name |store |
|____________________+____________________|
|MegaCorp Bobs Boutique |
|MegaCorp Pattyïs Pantstore |
|SuperStores Hanks Hardware |
|SuperStores Santos SuperStore |
+-----------------------------------------+
SELECT A1.name AS owner, SUM(A2.store_sales) AS Sales
FROM owners A1, stores A2
WHERE A1.store = A2.store_name
GROUP BY A1.name
|--------------------+--------------------|
|owner |Sales |
|____________________+____________________|
|MegaCorp 2300 |
|SuperStores 5500 |
+-----------------------------------------+
SELECT A1.name AS owner, SUM(A2.store_sales) AS Sales
SELECT owners.name AS owner, SUM(stores.store_sales) AS Sales
FROM owners A1, stores A2
WHERE A1.store = A2.store_name
There are no comments on this article.
If you have any question or just want to leave a message, just fill out the form below!
Your e-mail will not be visible in your post, it is for validation reasons only
Maffelu
Creator and admin of MorkaLork.com.
Started programming in HTML back when frames and tables was the way to design a page, moved on to Pascal/Delphi, PHP, javascript/jQuery, VB.NET/C#, Java and C++.
Currently studies .NET (in general) focusing on ASP.NET.