前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >数据库基础:select基本查询语句

数据库基础:select基本查询语句

作者头像
全栈程序员站长
发布2022-07-01 18:16:52
6330
发布2022-07-01 18:16:52
举报

大家好,又见面了,我是你们的朋友全栈君。

数据库基本查询语句规范为:select 区域 from 表名

查询指定表

select * from 表名

*:代表所有列

示例:select * from TL_REQUEST

查询指定列

select 列名 from 表名

列名:代表从指定的列名中查找

,:如果是查找对应的多列,则用英文逗号间隔

示例: select BU_NO from TL_REQUEST select BU_NO,BU_NM from TL_REQUEST

条件查询

select * from 表名 where 条件

*:代表所有列

条件:一般都是where加条件表达式

查询列里包含数字或字母:select * from 表名 where 列名=’值’

示例: select * from TL_REQUEST where BU_NO=’1234′ select * from TL_REQUEST where BU_NM=’小芳’

范围查询

select * from 表名 where 列名 between ‘A’ and ‘B’

select * from 表名 where 列名>=’A’ and 列名<=’B’

示例: select*from TL_REQUEST where BU_NO between ‘1000’ and ‘1234’ select*from TL_REQUEST where BU_NO>=’1000′ and BU_NO<=’1234′

多条件查询

或条件查询:or

select * from 表名 where 列名=’A’ or列名=’B’

示例:select * from TL_REQUEST where BU_NO=’1000′ or BU_NO=’1234′

和条件查询:and

select * from 表名 where 列名=’A’ and列名=’B’

示例:select * from TL_REQUEST where BU_NO=’1000′ and CONTRACT_NO=’tl001′

离散查询

包含值查询:in()

select * from 表名 where 列名=’A’ 列名=’B’ 列名=’C’

或:

select * from 表名 where 列名 in(‘A’,’B’,’C’)

示例: select * from TL_REQUEST where BU_NO=’1000′ BU_NO=’1234′ BU_NO=’1311′ 或: select * from TL_REQUEST where BU_NO in(‘1000′,’1234′,’1311’)

不包含值查询:not in()

select * from 表名 where 列名 not in(‘A’,’B’,’C’)

示例:select * from TL_REQUEST where BU_NO not in(‘1000′,’1234′,’1311’)

模糊查询

查询列里包含具体中文:select * from 表名 where 列名like ‘%中文%’

Like:名称前面加。

%:任意多个字符。

_:下划线表示任意一个字符。

示例:select * from TL_REQUEST where BU_NM like ‘%杜芳%’ 或查询第二个字符为芳的情况 select * from TL_REQUEST where BU_NM like ‘%_芳%’

去重查询

select distinct 列名 from 表名

示例:select distinct BU_NO from TL_REQUEST

组合查询

select distinct 列名 from 表名 where 条件

示例:select distinct BU_NO from TL_REQUEST where BU_NO between ‘1000’ and ‘1234’

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/130835.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 查询指定表
  • 查询指定列
  • 条件查询
  • 范围查询
  • 多条件查询
  • 离散查询
  • 模糊查询
  • 去重查询
  • 组合查询
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档