select * from court left join (province and area) on (province.id=area.p_id and province.id=cout.p_id and area.id=court.a_id) where court.id=?? 这样的东西?? 上面那个不能用的
表A记录如下:aID aNum1 a200501112 a200501123 a200501134 a200501145 a20050115表B记录如下:bID bName1 20060324012 20060324023 20060324034 20060324048 2006032408 创建这两个表SQL语句如下:CREATE TABLE a aID int( 1 ) AUTO_INCREMENT PRIMARY KEY , aNum char( 20 ) ) CREATE TABLE b( bID int(...
MySQL支持下列用于SELECT语句的join句法: table_reference, table_reference table_reference [CROSS] join table_reference table_reference INNER join table_reference table_reference STRAIGHT_join table_reference table_reference left [OUTER] join table_reference ON conditional_expr table_reference left [OUTER] join table_reference USING (column_list) table_reference NATURAL left [OUTER] join table_ref...
mysql> select * from emp; +-------+-------+--------+------+ | empno | ename | deptno | age | +-------+-------+--------+------+ | 1001 | wang | 10 | 20 | | 1002 | ang | 20 | 30 | | 1003 | ng | 10 | 20 | | 1004 | ling | 30 | 40 | | 1004 | dong | 40 | 40 | +-------+-------+--------+------+ 5 rows in set (0.00 sec) mysql> select * from dept; +--------+-----...
本文转自: http://www.wellho.net/archives/2004/12/index.html#000158 MySQL - left join and RIGHT join, INNER join and OUTER join In a database such as MySQL, data is divided into a series of tables (the "why" is beyond what I'm writing today) which are then connected together in SELECT commands to generate the output required. I find when I'm running MySQL training , people often get confused b...
示例表如下: select * from emp; +----+-----------+ | id | name | +----+-----------+ | 1 | Dennis-1 | | 2 | Dennis-2 | | 3 | Dennis-3 | | 4 | Dennis-4 | | 5 | Dennis-5 | | 6 | Dennis-6 | | 7 | Dennis-7 | | 8 | Dennis-8 | | 9 | Dennis-9 | | 10 | Dennis-10 | select * from emp_dept; +---------+--------+----------+ | dept_id | emp_id | emp_name | +---------+--------+----------+...
表 A: "A1","N1","B1" "A2","N2",NULL "A3","N3",NULL 表 B: "B1","BN" ======================== SELECT A.ID,A.NAME FROM A left OUTER join B ON A.BID=B.ID 结果: "A2","N2" "A3","N3" "A1","N1" SELECT A.ID,A.NAME FROM A left OUTER join B ON A.BID=B.ID WHERE B.ID = null OR null is null 结果: "A1","N1" 不正确 SELECT A.ID,A.NAME FROM A left OUTER join B ON A.BID=B.ID WHERE B.ID i...