开发者

SQL Query for fetching 5 rows from one column?

开发者 https://www.devze.com 2023-02-22 03:27 出处:网络
SQL query for f开发者_如何学运维etching five rows/data from one column?SELECT columnName FROM Table LIMIT 5

SQL query for f开发者_如何学运维etching five rows/data from one column?


SELECT columnName FROM Table LIMIT 5

or

SELECT columnName FROM Table WHERE anotherColumn = somevalue LIMIT 5

Or

SELECT columnName FROM Table WHERE anotherColumn = somevalue ORDER BY columnName1 asc LIMIT 5


SQL SERVER

SELECT TOP 5 ColumnName FROM TableName;

  • will return 5 records, but you won't know which ones unless the TableName is indexed by ColumnName or you sort by ColumnName
  • will return the requested number of rows if the table has as many or more rows than requested.


I think ORDER BY plays an important role in finalizing the 5 records

SELECT columnName FROM Table order by ID desc LIMIT 5 
0

精彩评论

暂无评论...
验证码 换一张
取 消