MySql数据库-06DDQL数据查询语言(上)

本文详细介绍了SQL中的基本查询方法,包括查询所有列和指定列的数据。此外,还深入讲解了如何利用条件进行精确查询,例如使用不同的运算符、关键字以及模糊查询的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一:基础

1 查询所有列(显示所有内容)
        select * from 表名;

2 查询指定列(显示指定查询列内容)

                select 列名1, 列名2, 列名3 from 表名;


二:条件查询

        条件查询就是在查询时给出where子句,在where子句中可以使用运算符及关键字:
1.  =、!=、<>、<、<=、>、>=
2.  in
3.             between ......and......
4. and 组合条件都是true 返回true
5. or    组合条件有一是true 返回true
                6. not   后面条件是true 返回false
                7. is  null ; is not null

        例1:进本条件符
            select * from user where name !='zhangsan';   等同  select * from user where name <>'zhangsan'; 
    
        例2:匹配指定值
            select * from user where age in(20,30,40);(查询所有age 是20,30,40 的人)
 
例3:匹配指定区间(包含)
            select * from user where age between 20 and 30;(查询所有age是20到30之间的人)


例4:匹配指定区间(与between...and...一样效果)
             select * from user where age>=20 and age<=30;


例5:匹配某个区间或者某个区间
             select * from user where age<20 or age age>30;  ( 查询所有age小于20的或者age大于30的人)     


        例6:表不是
              select * from user where not name='zhangshan';


例7:值是null;值不是null
             select * from user where name is null;
             select * from user where name is not null;
   


三:   模糊查询:不清楚的查询,模糊查询需要使用关键字like。
   通配符: 
     _: 任意一个字符
  %:任意0~n个字符


语法:
    select 字段 from  表名  where 某字段 Like 条件。
        例:select * from user where name like '张%';   (查询所有姓张的用户)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值