AD

SQL based series --- left join

1.left join will be left to return all the rows in the table, even if the right table does not match the line.
2.LEFT JOIN keyword syntax
SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2 
ON table_name1.column_name=table_name2.column_name

Note: In some databases, LEFT JOIN is called LEFT OUTER JOIN.
The original table (used in the case of):
"Persons"  Table  :
Id_P    LastName        FirstName       Address City
1       Adams   John    Oxford Street   London
2       Bush    George  Fifth Avenue    New York
3       Carter  Thomas  Changan Street  Beijing

"Orders" table:
Id_O  OrderNo Id_P
1       77895   3
2       44678   3
3       22456   1
4       24562   1
5       34764   65

Left connection (LEFT JOIN) instances now, we hope all the people listed and their order - if any.
You can use the following SELECT statement:
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
FROM Persons
LEFT JOIN Orders
ON Persons.Id_P=Orders.Id_P
ORDER BY Persons.LastName

Result set:
LastName   FirstName       OrderNo
Adams   John    22456
Adams   John    24562
Carter  Thomas  77895
Carter  Thomas  44678
Bush    George   

LEFT JOIN keywords from the left table (Persons), where all the rows returned, even in the right table (Orders) does not match the line.
标签: column name, databases, select statement, instances, table id, address city, oxford street london, bush george, fifth avenue new york
分类: Database
时间: 2010-09-26

相关文章

  1. SQL based series --- right join

    1.right joinR keyword will return all rows from right table, even if there is no match in the left table rows. ...
  2. SQL based series --- full join

    1.full join keywords that match as long as there is a table which, on the return trip 2.FULL JOIN keyword synt ...
  3. SQL based series ------ union operator

    1.UNION operator to combine two or more SELECT statement result sets. Please note, UNION SELECT statement must ...
  4. Series 2 ------ JOIN SQL basis

    1. Database table can be linked to each other through the bond will be. Primary key (Primary Key) is a column ...
  5. Series II ------ JOIN SQL basis

    1 table in the database can be linked to each other through the key. Primary Key (Primary Key) is a column in ...
  6. Turn: oracle sql optimization Series

    Keyword ORACEL SQL Performance tuning Source http://www.dbasupport.com 1 choice for the ORACLE optimizer ORACL ...
  7. sql conversion hql left join problem

    I do not know the following sql statement on how this form of written hql select count (*) from (select rydm f ...
  8. sql based document questions

    Now we assume that only one table, called pages, there are four fields, id, url, title, body. Save a lot of in ...
  9. Oracle PL / SQL based

    Each database has its own unique language, Oracle is PL_SQL the following. It is relative to the SQL language, ...
  10. basic knowledge of oracle sql based

    1. Sql (Structured Query Language) is the basic operation of the relational database language. Including datab ...
  11. SQL connection (inner, left join, right outer joins, self-connection) Detailed

    create table department( id number primary key, name varchar2(30)); create table employee( id number primary k ...
  12. PL / SQL based and uses the variables defined

    • Introduction In writing PL / SQL procedure, you can define variables and constants; in PL / SQL program incl ...
  13. SQL Studying Note I - Join

    SQL Join SQL Join are used very frequently to query data from 2 or more tables, base on the relationship betwe ...
  14. SQL中的left join right join

    数据库常见的join方式有三种:inner join, left outter join, right outter join(还有一种full join,因不常用,本文不讨论).这三种连接方式都是将两个以上的表通过on ...
  15. SQL with NUll处理,Join系列,between,in对比exists以及少量题目

    1.一些题目: 选择在每一组B值相同的数据中对应的a最大的记录的所有信息,(用于论坛每月排行榜) Selecta,b,c from tableta wherea=(select max(a) from tabletb w ...
  16. mysql sql upgrade series barefoot

    What is a sql? sql is the core of relational database management system is a database server (DBMS) to interac ...
  17. sql based on [a common face questions]

    - Create database Dom - On - ( - Name = 'Dom_MDF', - Filename = 'E: \ Dom_Dom.mdf', - Size = 3mb, - Maxsize = ...
  18. Flash based series of high-performance development - data container

    This section is AS version of the data structures and algorithms, the performance bottleneck in the AS in the ...
  19. sql in an inner join. left to connect. the right connections. fully connected

    Table A: AID ANAME BID ---- -------------------- ---------- 1 a1 2 2 a2 3 3 a3 4 4 a4 5 Table B: BID BNAME --- ...