当前位置:Gxlcms > 数据库问题 > 数据库的查询

数据库的查询

时间:2021-07-01 10:21:17 帮助过:16人阅读

高级查询


1.连接查询.对结果集列的扩展
select * from info,nation 会形成笛卡尔积,数据量大不建议使用连接查询
select * from info,nation where info.nation=nation.code
select * from info join nation on info.nation=nation.code

2.联合查询.对结果集行的扩展
select code.name from info(info里面的code)
union(联合)
select code.name from nation(nation里面的code)
查询的列的数量要相同

3.子查询

父查询(外层查询)
子查询(里层查询)

子查询查询出来的结果作为父查询的条件

①无关子查询
子查询在执行的时候和父查询没有关系(子查询可以单独执行)
父查询:select *from info where nation=()
子查询:select code from nation where name=‘汉族’
子查询查询出的条件可以作为父查询的条件
select * from info where nation=(子查询)

②相关子查询
子查询在执行的时候和父查询有关系(子查询不可以单独执行)

在查询中父查询会等待子查询查询完毕才会执行下一条父查询,子查询不能单独执行。

数据库的查询

标签:子查询   where   code   nio   条件   inf   查询   高级   name   

人气教程排行