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
精彩评论