SQL常用的一些語句《非常容易忘記的》

2021-08-23 14:00:55 字數 1272 閱讀 8758

一,查詢

取倒數第二條資料:

select * from (select * from shop order by 'article' desc limit 2) as b order by 'article' asc limit 1;

聯合查詢:

select w.webname, w.owner, w.customercode,c.agentid, c.certype, c. cerid,c.customername from `webinfo` as w, `customerinfo` as c where w.customercode = c.customercode;

不顯示重複字段資料:

select distinct name from test;

二,更新

update `message` set `gowhere` = 'smsaddr' where `gowhere` = 'smsaddress' limit 1 ;

三,刪除

delete student where id=1;

drop database test;(慎用)

drop table student;(慎用)

四,建立

create table `student` (

`id` int(11) not null auto_increment,

`name` varchar(20) default null,

`stuno` varchar(20) default null,

`starttime` date default null,

primary key (`id`)

) engine=myisam default charset=utf8 max_rows=4;

五,增加

insert into employees values (1,"bob","smith","128 here st", "marketing manager");

insert into student (id,name,stuno,starttime) values (1,"fordream","xyzx55888","2003-01-02");

六,其它

mysql改變編碼

alter table salary default character set utf8 collate utf8_bin;

給某錶增加一欄位

alter table `message` add `gowhere` varchar( 10 ) not null ;

一些常用的 sql語句總結

查詢賣最好的商品名稱 select goods name from indent detail group by goods id order by sum goods num limit 1 查詢張三購買過的商品名稱 select goods name from user join indent ...

MySQL的一些常用SQL語句

備份表 create table 新錶 select from 舊表 建立臨時表 create temporary table tablename id varchar 100 name varchar 100 age varchar 100 刪除臨時表 drop temporary table i...

關於一些常用的SQL語句

增加欄位並標明備註 alter table test add test name varchar 220 comment 名稱 刪除的話,在實際情況中最好不要刪除資料,可以增加棄用的狀態去控制 表備份 備份test 表生成test new 新錶的命名根據你們的具體要求來 create table t...