ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SQL string to return top row (https://www.excelbanter.com/excel-programming/286524-sql-string-return-top-row.html)

quartz

SQL string to return top row
 
Hello, please help if possible.

Does anyone know what the SQL string would look like to
return ALL columns for a specific number of rows (or just
the top row) of an Access DB (along with the headers)?

I've tried things like:

SELECT * FROM [TABLE] WHERE ROWNUM = 1;

but Access apparently doesn't use "ROWNUM".

Your example string would be most helpful. TIA.

Jake Marx[_3_]

SQL string to return top row
 
Hi Quartz,

You can use the TOP n expression to do that. Basically, the database will
return the top n row(s) that meet the criteria. For example, if you wanted
the top 5 records from a table named tblEmployees where the employee's last
name starts with "S", you would do this:

SELECT TOP 5 *
FROM tblEmployees
WHERE LastName LIKE 'S*'
ORDER BY LastName ASC

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Quartz wrote:
Hello, please help if possible.

Does anyone know what the SQL string would look like to
return ALL columns for a specific number of rows (or just
the top row) of an Access DB (along with the headers)?

I've tried things like:

SELECT * FROM [TABLE] WHERE ROWNUM = 1;

but Access apparently doesn't use "ROWNUM".

Your example string would be most helpful. TIA.




All times are GMT +1. The time now is 05:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com