Mysql之SQL語句 select聯表查詢

2021-10-22 09:22:48 字數 740 閱讀 2319

1.連表查詢

現有表1:student 列1:d 列2:name 和 表2:score 列1:id 列2:fraction

select student.name,score.fraction from student,score where student.id=1 and score.id=1; #查詢1號id的成績

或者select student.name,score.fraction from student,score where student.id=score.id and name=』xiaohuang』; #查詢xiaohuang的成績

2.自連線查詢 自連線的表必須要有共同的列和資料

select student.name,score.fraction from student natural join score where id=3;

3.內連線查詢

select * from 表1 join 表2 on 關聯條件 where 條件;

select student.name,score.fraction from student join score on student.id=score.id where name=』xiaohong』;

MySQL許可權篇之DELETE及SELECT

delete許可權,該許可權僅僅能刪除表中的記錄。但是要注意如果僅僅只授予了delete許可權。比如 mysql show grants for ut01 grants for ut01 grant usage on to ut01 1 row in set 0.00 sec mysql grant...

mysql之常用SQL語句

檢視資料庫 show databases 進入切換資料庫 use 資料庫名 use crushlinux 檢視表 show tables 新建資料庫,新建表 create database 庫名 create database yi create table 表名 欄位一,欄位2 create ta...

Mysql之SQL語句(上篇)

1.create database 庫名 建立資料庫 2.create database 庫名 charset utf8 collate utf8 general ci 指定字符集和校驗規則建立資料庫 3.show databases 檢視資料庫內的所有庫 4.show create databas...