如何编写一个简单的数据库查询语句?

如何编写一个简单的数据库查询语句?

示例数据:

| ID | Name | Age | City | |---|---|---|---| | 1 | John | 25 | New York | | 2 | Mary | 30 | London | | 3 | Peter | 45 | Paris | | 4 | Sarah | 20 | Berlin |

查询语句:

SELECT Name, Age, City FROM table_name;

解释:

  • SELECT specifies the columns to be retrieved. In this case, it selects Name, Age, and City.
  • FROM specifies the table to be queried. In this case, it's table_name.
  • WHERE is optional. It filters the results based on a condition. In this case, it doesn't have any conditions.

执行查询:

SELECT Name, Age, City FROM table_name;

结果:

| Name | Age | City |
|---|---|---|
| John | 25 | New York |
| Mary | 30 | London |
| Peter | 45 | Paris |
| Sarah | 20 | Berlin |

注意:

  • 您可以使用不同的关键字来替换 SELECT, FROM, and WHERE
  • 您可以使用 ORDER BY 来排序结果。
  • 您可以使用 LIMIT 来限制结果数量。
相似内容
更多>