back up codes

always have a backup of your code

Archive for the tag “sql top”

sql TOP clause

The SQL TOP clause is used to specify the number of records to retrieve.

When retrieving large number of records are done, the performance is affected. The TOP clause is useful on tables with very large number of records.

The sysntax is the following:

SELECT TOP NUMBER|PERCENT myColumn(s)
FROM myTable

Here are two examples

SELECT TOP 30 PERCENT * FROM myTable
SELECT TOP 3 * FROM myTable

select the first row in sql select statement

The following sql statement will retrieve the first row from a select statement:


SELECT TOP 1 * FROM MY_TABLE ORDER BY THE_PK DESC

select the second row in a select statement

The following code will select the second row in an sql select statement.


SELECT TOP 1 * FROM (SELECT TOP 2 * FROM MY_TBL ORDER BY MY_DATE ASC ) AS VALUE ORDER BY MY_DATE ASC

Post Navigation

Follow

Get every new post delivered to your Inbox.