SQL入门-DQL数据查询语言--select

1.help select

mysql> help select
Name: ‘SELECT‘
Description:
Syntax:
SELECT
    [ALL | DISTINCT | DISTINCTROW ]
      [HIGH_PRIORITY]
      [STRAIGHT_JOIN]
      [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
      [SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
    select_expr [, select_expr ...]
    [FROM table_references
      [PARTITION partition_list]
    [WHERE where_condition]
    [GROUP BY {col_name | expr | position}
      [ASC | DESC], ... [WITH ROLLUP]]
    [HAVING where_condition]
    [ORDER BY {col_name | expr | position}
      [ASC | DESC], ...]
    [LIMIT {[offset,] row_count | row_count OFFSET offset}]
    [PROCEDURE procedure_name(argument_list)]
    [INTO OUTFILE ‘file_name‘
        [CHARACTER SET charset_name]
        export_options
      | INTO DUMPFILE ‘file_name‘
      | INTO var_name [, var_name]]
    [FOR UPDATE | LOCK IN SHARE MODE]]

SELECT is used to retrieve rows selected from one or more tables, and
can include UNION statements and subqueries. See [HELP UNION], and
http://dev.mysql.com/doc/refman/5.6/en/subqueries.html.

The most commonly used clauses of SELECT statements are these:

o Each select_expr indicates a column that you want to retrieve. There
  must be at least one select_expr.

o table_references indicates the table or tables from which to retrieve
  rows. Its syntax is described in [HELP JOIN].

o Starting in MySQL 5.6.2, SELECT supports explicit partition selection
  using the PARTITION keyword with a list of partitions or
  subpartitions (or both) following the name of the table in a
  table_reference (see [HELP JOIN]). In this case, rows are selected
  only from the partitions listed, and any other partitions of the
  table are ignored. For more information and examples, see
  http://dev.mysql.com/doc/refman/5.6/en/partitioning-selection.html.

  In MySQL 5.6.6 and later, SELECT ... PARTITION from tables using
  storage engines such as MyISAM that perform table-level locks (and
  thus partition locks) lock only the partitions or subpartitions named
  by the PARTITION option.

  See
  http://dev.mysql.com/doc/refman/5.6/en/partitioning-limitations-locki
  ng.html, for more information.

o The WHERE clause, if given, indicates the condition or conditions
  that rows must satisfy to be selected. where_condition is an
  expression that evaluates to true for each row to be selected. The
  statement selects all rows if there is no WHERE clause.

  In the WHERE expression, you can use any of the functions and
  operators that MySQL supports, except for aggregate (summary)
  functions. See
  http://dev.mysql.com/doc/refman/5.6/en/expressions.html, and
  http://dev.mysql.com/doc/refman/5.6/en/functions.html.

SELECT can also be used to retrieve rows computed without reference to
any table.

URL: http://dev.mysql.com/doc/refman/5.6/en/select.html

2.select 可以不使用from 子句

select user();

3.指定查询条件,使用数据过滤的更加准确

select user,host,password from mysql.user;

4.模糊查询

select user,host,password from mysql.user where user like ‘roo%‘;

 5.排序order by

--降序排列
select * from anyuxweb.t2 order by id desc;
--升序排列
select * from anyuxweb.t2 order by id asc;

6.limit 使用

select * from anyuxweb.t2 order by id asc limit 1,2;

原文地址:https://www.cnblogs.com/anyux/p/8127170.html

时间: 2024-10-13 22:56:39

SQL入门-DQL数据查询语言--select的相关文章

八:SQL之DQL数据查询语言单表操作

前言: DQL数据库查询语言是我们在开发中最常使用的SQL,这一章总结了单表操作部分的常用查询方式 主要操作有:查询所有字段.查询指定字段.查询指定记录.带IN的关键字查询,范围查询,陪查询.查询空值 带AND的多条件查询.带OR的多条件查询,关键字DISTINCT,查询结果排序,分组查询.分页查询等 准备好数据测试表 1 mysql> select * from student; 2 +------+----------+-------+----------+-------------+ 3

数据存储——SQLite数据库存储——SQL语句——DQL数据查询语言

一.where  查询条件 1.操作符 (1)is null/is not null  判断控/非空 (2)like  模糊比较字符串 ①通配符 1)%  任意数量字符 2)_   单个字符 ②用法 1)like  ‘%条件%’ 2)like  ‘%条件’ 3)like  '条件%' 4)like  '_条件_' 5)like  '_条件' 6)like  '条件_' (3)in  判断是否在值得列表内 ①和对单个字段  or  运算等效 ②用法 1)字段名 in (值1,值2,...) 2)字

九:SQL之DQL数据查询语言多表操作

前言: 一:数据准备 员工表emp 和部门表 dept --分别创建部门和员工表,并实现一对多关系 DROP TABLE dept; CREATE TABLE `dept`( `d_id` INT(5) PRIMARY KEY AUTO_INCREMENT COMMENT '这是部门id主键自增长', `d_name` VARCHAR(30) NOT NULL UNIQUE COMMENT '这是部门名称唯一非空' ); CREATE TABLE `emp`( `e_id` INT PRIMAR

SQL之检索数据(select语句)

1.keywords(关键字) 关键字不能用作表或者列的名字. 2.1检索单个列 select prod_namefrom Products; 上述语句从Products表中检索一个名为prod_name的列.Select关键字后面是列名,from关键字后面是表名. 多条SQL语句必须用分号(;)间隔,单条SQL最好后面也加上分号. SQL语句是不区分大小写的.所有的空格都是被忽略的. 2.2检索多个列 select prod_id,prod_name,prod_pricefrom Produc

DQL 数据查询语言 IS (information_schema)

3.information_schema 统计信息库 1.介绍: 视图 1.安全: 只允许查询,不知道操作的对象是谁. 2.方便: 只需要简单的select语句即可使用. 2.作用: 1.方便我们做数据库资产统计 库/表: 个数 数据量(容量:行数) 每张表的数据字典信息 2.可以获取到server层状态信息 3.获取到InnoDB引擎层的状态信息 3.应用举例: TABLES : TABLE_SCHEMA: 表所在的库 TABLE_NAME: 表名 ENGINE : 表的引擎 TABLE-RO

DQL 数据查询语言

1.select 1.select 单独使用 (1) 查询数据库的参数 查看端口: select @@port; 查看数据路径 select @@datadir; (2)调用内置函数 查看当前库 select database(); CONCAT 将内容拼接 select concat(user,host) from mysql.user; select concat(user,'@',host) from mysql.user; 列转行 select group_concat(xid) fro

数据存储——SQLite语句之DQL 数据查询语言

一.select 语句 格式:select   字段内容  from  表名 1.字段列表 1-*全部字段 2-逗号间隔的字段名列表 3-用as(可省略)指定别名 2.DISTINCT去重复数据:DISTINCT  字段列表 二.where  查询条件 1.is null/is not null   判断空/非空 2.like  模糊比较字符串 1-通配符 1>%任意数量字符 2>_单个字符 2-用法 1>like‘%条件’ 2>like‘条件%’ 3>like‘%条件%’

MySQL数据库之DQL(数据查询语言)

1.MySQL之DQL查询AS CONCAT LIKE的使用 (1)select 列名1,列名2,...... from 表名 [where 条件] 查询所有字段用*,不带where条件的话,就会把表的所有记录查出来 (2)过滤掉重复的列值 select distinct 列名1 from 表名; (3)连接concat select concat(列名1,列名2) from 表名; select concat_ws('分隔符',列名1,列名2) from 表名; 区别:用concat查询出来的

DQL数据查询语言——连接查询

--内连接 两种写法 等值连接select r.*,b.bummc from t_hq_ryxx r, t_hq_bm b where r.bumbm = b.bumbm select r.*,b.bummc from t_hq_ryxx r inner join t_hq_bm b on r.bumbm = b.bumbm --不等值连接select r.*,b.bummc from t_hq_ryxx r, t_hq_bm b where r.bumbm > b.bumbm select r