" /> Password <br /><input type="password" name="passwd" id="passwd" class="inputbox" size="18" alt="password" />
PDF Note

1
2
3
4
SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON =table_name2.column_name

- Note: В некоторых базах данных имеет имя LEFT OUTER JOIN.

Пример SQL

There is a table "Persons":

P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger

O_Id OrderNo P_Id
1 77895 3
2 44678 3
3 22456 1
4 24562 1
5 34764 15

For this we use this query:

1
2
3
4
5
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
FROM Persons
LEFT JOIN Orders
ON Persons.P_Id=Orders.P_Id
ORDER BY Persons.LastName

Query Result:

LastName FirstName OrderNo
Hansen Ola 22456
Hansen Ola 24562
Pettersen Kari 77895
Pettersen Kari 44678
Svendson Tove

Comments

 
-1 #1 Nerses 2010-10-04 13:56 Please tell me how do you make in order to result table rows show one Hansen,
your result table have Two Hansen,
Quote
 
 
+8 #2 aquillaman 2010-10-17 17:43
Please tell me how do you make in order to result table rows show one Hansen,
your result table have Two Hansen,

It's because of in second table "Orders" we have two orders with Hansen's P_Id (3)
Quote
 
 
+4 #3 aquillaman 2010-10-17 17:44
Please tell me how do you make in order to result table rows show one Hansen,
your result table have Two Hansen,

It's because of in second table "Orders" we have two orders with Hansen's P_Id (3)

Hansen's P_Id = 1
Quote
 
 
+10 #4 INet 2011-02-25 14:50 Excellent! clearly understandable! Quote
 
 
+2 #5 skinny 2011-03-19 19:19 yes all is well painted and clear and understandable!! Quote
 
 
+3 #6 Krot 2011-03-31 20:01 Thank you. Until the end of enlightenment has not come yet, but I'm working on it)) Quote
 
 
0 #7 Member 2011-03-31 22:52 Thank you for your good example. Could you explain how to build a query that would result has been merged into rows and count the number of orders. Ie that would result had the look of the columns LastName, FirstN ame, count(order):
Hansen, Ola 2
Pettersen, Kari 2
Svendson Tove zero
Quote
 
 
+1 #8 Alex-x 2011-04-29 11:43 #7 Member 2011-03-31 22:52
Count on the right list
Quote
 
 
0 #9 Allexxisss 2012-02-28 15:30 Quote
 

Authorization

Nice Ajax Poll

Which one of my extensions is the best?

Statistics

Advertisement