One side questions: create several data tables, write in connection. Left outer join. Sub-query sql, and explain the significance of doing so.

2010-03-25  来源:本站原创  分类:Database  人气:264 

Create a number of data tables, write Inner Join, Left Outer Join, sub query sql, and explain the significance of doing so.

The following is a personal answer, for reference:

create table a (aid int (10), aname varchar (20));
create table b (bid int (10), bname varchar (20));
Table a data
aid aname
1 a1
2 a2
3 a3
Table b data
bid bname
1 b1
2 b2
4 b4

In connection inner join:
select * from a inner join b on a.aid = b.bid
Get data:
1 a1 b1
2 a2 b2
If no matching row within the connection, then the associated result set row in the select list of all the right table columns are null

Left link left join:
select * from a left join b on a.aid = b.bid
Get data:
1 a1 b1
2 a2 b2
3 a3 null

Left out join the result set, including left outer left table specified in clause all rows, not just join the line out the match.
If the right of left table rows of a table, left the table (a) the record will be all that out, while the right table (b) will only show the records meet the search criteria (eg: a.aid = b.bid)
left join is a table based on the record, a table can be seen as the left, b can be seen as the right table, left join the table is left as the yardstick.

Subquery:
select * from a where a.aid in (select bid form b)
For the query appears in the b table bid is equal to a table of aid to all the records.

相关文章