当前位置:网站首页>SQL basic query
SQL basic query
2022-06-11 08:52:00 【Lizexin】
Basic query method :
select Field from Table name ;
select * from Table name ;
duplicate removal
select distinct Field from Table name ;
Basic condition query
select Field from Table name where Conditions Operator value ;
| Operator | name |
|---|---|
| = | be equal to |
| <> | It's not equal to |
| > | Greater than |
| < | Less than |
| >= | Greater than or equal to |
| <= | Less than or equal to |
| BETWEEN | In a certain range |
| LIKE | contain |
notes :
In some versions of sql in , The operator <> Can be written as !=.
sql Use single quotation marks in to surround the text value ( Most database systems also accept double quotes ), Values don't use quotation marks .
and and or Operator
and: If the first condition and the second condition hold , be and Operator to display a record .
or: If only one of the first condition and the second condition holds , be or Operator to display a record .
select Field from Table name where Field Operator value and/or Conditions Operator value ;
notes :and And or combination ( Use parentheses to form complex expressions )
select Field from Table name where ( Conditions Operator value and/or Conditions Operator value ) and/or Conditions Operator value ;
order by Default sort
desc In reverse order
select Field from Table name order by or desc;
Insert
insert into Table name values ( value 1, value 2,...);
insert into Table name ( Field 1, Field 2) voalues ( value 1, value 2,...);
modify
update Table name set Field = The new value where Field = Certain value ;
Delete
drop Delete table : Delete content and definition , Release space
drop table Table name ;
delete Delete content , Do not delete table structure , Delete line by line
delete table Table name ;
delete from Table name where Conditions = value ;
truncate Delete content 、 Release space , But don't delete the table structure ;
truncate table Table name ;
like Fuzzy query
select Field from Table name where Field like 'N%';
notes :“%” Can be used for the first wildcard
wildcard describe
% Replace one or more characters
_ Replace only one character
[charlist] Any single character in the character column
[^charlist] perhaps [!charlist] Any single character not in the character column
in
select Field from Table name where Field in (value1,value2,...);
between…and Select a data range between two values , These values can be numerical 、 Text or date .
select Field from Table name where Field between value1 and value2;
Alias Alias
The table alias :
select Field from Table name as name ;
The alias of the field :
select Field as name from Table name ;
join
join The field contents and values are consistent inner join Internal connection : The result is the intersection of the two sides
select Field from Table name 1 inner jion Table name 2 on Table name 1. Field = Table name 2. Field
left join Left connection : Based on the table on the left , Whether the conditions are met or not, all the data on the left will be displayed , The data on the right shows only those that can be matched , Use when it doesn't match null fill ;
select Field from Table name 1 left jion Table name 2 on Table name 1. Field = Table name 2. Field
right join The right connection : The way of understanding is the same as the left connection , It's just that the table on the right is used as the benchmark , To match the data on the left , Only those that can be matched are displayed , No match null fill ;
select Field from Table name 1 right jion Table name 2 on Table name 1. Field = Table name 2. Field
FULL OUTER JOIN: Full connection , The result is a table A And table B Union , That is to say, it will all be displayed
SELECT Field
FROM surface 1
FULL OUTER JOIN surface
ON surface 1. Field = surface 2. Field ;
Cross join: Cross connect
SELECT Field FROM surface 1 CROSS JOIN surface 2 WHERE Conditions ;
or
SELECT Field FROM surface 1, surface 2 WHERE Conditions ;
union Inside select Statements must have the same number of columns .
Columns must be of the same type , At the same time, the column name order must be the same .
Different types can be cast cast ( Field as type :int float double varchar char etc. )
select Field from Table name 1
union
select Field from Table name 2
notes : Default union Operator selects different values , If duplicate values are allowed , You can use union all.
select into Add temporary table
select into Statement selects data from a table , Then insert the data into another temporary table .
select * into A temporary table from old surface ;
select * into A temporary table from old surface where Conditions Operator value ;
select count()
count(*) Function returns the number of record rows in the table :
select count(*) from Table name ;
select sum ()
sum Function returns the total number of columns of numbers ( Total ).
select sum( Field ) from Table name ;
notes : Usually cooperate group by Use ;
group by
group by Used to combine the total function , Group result sets according to one or more columns ;
select Field 1,sum( Field 2) from Table name group by Field 1;
边栏推荐
- 处理RAW格式的图像,需要什么软件?
- Sword finger offer 51 Reverse pair in array
- [cvpr2022] intensive reading of querydet papers
- Award winning survey | how Apache pulsar lived in 2022, you the final say
- MySQL死锁问题如何解决?背诵版
- Sword finger offer 40 Minimum number of K
- Oracle learning (I)
- 【C语言-函数栈帧】从反汇编的角度,剖析函数调用全流程
- 知识图谱入门之---yedda标注
- leetcode - 739. 每日温度
猜你喜欢

经典图论,深度优先和广度优先,拓扑,Prim和Krukal,该来温习啦

深度学习入门之pytorch安装

Can not connect to local MySQL server through socket ‘/tmp/mysql. sock (2)‘

Screening frog log file analyzer Chinese version installation tutorial

How to apply for BS 476-7 sample for display? Is it the same as the display

B+ super tree helps you know the underlying structure of MySQL
![[software tools] screen recording software captura](/img/79/705bb40fc15322243880f3b9864f2b.jpg)
[software tools] screen recording software captura

【C语言-数据存储】数据在内存中是怎样存储的?

剑指 Offer 40. 最小的k个数

Android 面试笔录(精心整理篇)
随机推荐
En45545-2 R26 vertical combustion test introduction
SAP material master data archiving
leetcode - 518. Change II
c语言打印心形
leetcode - 460. LFU 缓存
光伏板怎么申请ASTM E108阻燃测试?
for in / for of / forEach 循环
Are the two flame retardant standards of European furniture en 597-1 and en 597-2 the same?
Introduction to database system experiment report answer Experiment 6: advanced query of data table
使用express+mysql创建一个基于nodejs的后台服务
Getting started with Zipkin
How to apply for BS 476-7 sample for display? Is it the same as the display
c的printf相关
Oracle learning (I)
Matlab学习8-图像处理之线性与非线性锐化滤波、非线性平滑滤波
[software tool] the hacker matrix special effect software CMatrix
[software tool] installation ffmpeg
Redis6 entry-level tutorial. There are integration cases. You can directly see the integration cases. It is easy to get started
Wood board ISO 5660-1 heat release rate mapping test
显示器要申请BS 476-7 怎么送样?跟显示屏一样吗