E-mail Print PDF

Синтаксис SQL

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

Note - Note: В некоторых базах данных имеет имя RIGHT 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
RIGHT 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
34764

Comments

 
-1 #1 McKinseyBA 2010-06-11 11:55 I guess it makes sense to bring more tangible evidence, as a result of using Right Join and Left Join to existing similar, that is not conducive to the assimilation of the differences (if you do not grasp the meaning of his hat)

In general, the resource - fine, by - well done!
Quote
 
 
-1 #2 Валерий 2010-06-13 10:34 Yes, agree with previous petition .. I did not understand what LEFT RIGHT from different .. What is there about the output target, even if it is not one of the tables Quote
 
 
+2 #3 Артем 2010-06-16 09:18 Well, I understand))
author thanks for the examples
they would have more then just do a class!
Quote
 
 
0 #4 StitchUA 2010-06-18 10:20 Well, if it is not clear, look here: ru.wikipedia.org/.../Join_(SQL) Quote
 
 
+4 #5 Alex 2010-07-13 12:47 Tupite not all that can be described here
Do-what could be more exceptions to describe ...
Quote
 
 
+2 #6 Misha 2010-11-14 02:09 Something I do not really understand how a table tally derived from the condition "Now we want to get a list of all persons and their orders from the table above." After all, we get a list of all the orders and those who made the order, but such an order for 34 764 no person is present. The person named Svendson generally not present in the resulting table, so we did not get a list of all persons. Quote
 
 
+2 #7 dd 2011-03-04 13:54
Something I do not really understand how a table tally derived from the condition "Now we want to get a list of all persons and their orders from the table above." After all, we get a list of all the orders and those who made the order, but such an order for 34 764 no person is present. The person named Svendson generally not present in the resulting table, so we did not get a list of all persons.

simply beguiled by LEFT JOIN and
Quote
 

Authorization

Nice Ajax Poll

Which one of my extensions is the best?

Statistics

Translate

русскийitalianoDeutschEnglishLATVIANукраїнськаfrançaispolski
1

Advertisement