Mysql常用sql語句(20) 子查詢重點知識

2022-01-19 15:08:57 字數 767 閱讀 6267

測試必備的mysql常用sql語句系列

啥意思??

查詢sql 語句的組成一般是這樣

select

《字段》

from

《表名》

where

《查詢條件》

字段、表名、查詢條件都可以巢狀子查詢!

select

《子查詢》

from

《表名》

where

《查詢條件》

select

《字段》

from

《子查詢》

as《別名》

where

《查詢條件》

select

《字段》

from

《表名》

where

《子查詢》

常見錯誤寫法

select

*from (select

*from emp);

這樣寫是會報錯的,因為沒有給子查詢指定別名

正確寫法

select

*from (select

*from emp) as t;

注意點如果《表名》巢狀的是子查詢,必須給表指定別名,一般會返回多行多列的結果集,當做一張新的臨時表

Mysql常用sql語句(20) 子查詢重點知識

測試必備的mysql常用sql語句系列 啥意思?查詢sql 語句的組成一般是這樣 select 字段 from 表名 where 查詢條件 字段 表名 查詢條件都可以巢狀子查詢!select 子查詢 from 表名 where 查詢條件 select 字段 from 子查詢 as 別名 where ...

MySql 常用SQL語句

create database kali use kali show tables create table students sno varchar 10 primary key,sname varchar 10 not null,varchar 2 check in 男 女 age varcha...

常用sql語句(mysql)

給表新增列 sql alter table table name add column col name varchar 255 not null default default value 增加表列,指定格式 sql alter table table name add col name bool...