SQL SELECT 语句用于从数据库表中获取数据,该数据库表以输出表的形式返回该数据,这些输出表称为输出集。
Select Query - 语法
SELECT语句的基本语法如下-
SELECT column1, column2, columnN FROM table_name;
在这里,column1,column2 ...是要获取其值的表的字段。如果要获取该字段中所有可用的字段,则可以使用以下语法。
SELECT * FROM table_name;
Select Query - 示例
考虑具有以下记录的CUSTOMERS表-
+----+----------+-----+-----------+----------+ | ID | NAME | AGE | ADDRESS | SALARY | +----+----------+-----+-----------+----------+ | 1 | Ramesh | 32 | Ahmedabad | 2000.00 | | 2 | Khilan | 25 | Delhi | 1500.00 | | 3 | kaushik | 23 | Kota | 2000.00 | | 4 | Chaitali | 25 | Mumbai | 6500.00 | | 5 | Hardik | 27 | Bhopal | 8500.00 | | 6 | Komal | 22 | MP | 4500.00 | | 7 | Learnfk | 24 | Indore | 10000.00 | +----+----------+-----+-----------+----------+
以下代码为示例,它将获取CUSTOMERS表中可用客户的ID,名称和薪水字段。
SQL> SELECT ID, NAME, SALARY FROM CUSTOMERS;
这将产生以下输出-
+----+----------+----------+ | ID | NAME | SALARY | +----+----------+----------+ | 1 | Ramesh | 2000.00 | | 2 | Khilan | 1500.00 | | 3 | kaushik | 2000.00 | | 4 | Chaitali | 6500.00 | | 5 | Hardik | 8500.00 | | 6 | Komal | 4500.00 | | 7 | Learnfk | 10000.00 | +----+----------+----------+
如果要获取CUSTOMERS表的所有字段,则应使用以下查询。
SQL> SELECT * FROM CUSTOMERS;
这将产生如下所示的输出。
+----+----------+-----+-----------+----------+ | ID | NAME | AGE | ADDRESS | SALARY | +----+----------+-----+-----------+----------+ | 1 | Ramesh | 32 | Ahmedabad | 2000.00 | | 2 | Khilan | 25 | Delhi | 1500.00 | | 3 | kaushik | 23 | Kota | 2000.00 | | 4 | Chaitali | 25 | Mumbai | 6500.00 | | 5 | Hardik | 27 | Bhopal | 8500.00 | | 6 | Komal | 22 | MP | 4500.00 | | 7 | Learnfk | 24 | Indore | 10000.00 | +----+----------+-----+-----------+----------+
参考链接
https://www.learnfk.com/sql/sql-select-query.html
标签:+----+----------+-----+-----------+----------+,25,CUSTOMERS,2000.00,无涯,Select,SQ From: https://blog.51cto.com/u_14033984/9255112