Unified SQL for TOP n or LIMIT n
Posted: Wed 05 May 2010 04:33
Hi,
I was trying to come up with a good way of specifying TOP 1 or LIMIT 1 when using SQL Server or PostgreSQL DB's.
For now I have defined macros {TOP_1} and {LIMIT_1} and a typical query look like this:
SELECT {TOP_1} ID FROM SOME_TABLE {LIMIT_1}
Where {TOP_1} is defined for SQL Server and {LIMIT_1} is defined for PostgreSQL.
This isn't very clever for TOP 5 or LIMIT 10 though...
Is there a clever way to do it?
Thanks in advance,
Regards, Paul.
I was trying to come up with a good way of specifying TOP 1 or LIMIT 1 when using SQL Server or PostgreSQL DB's.
For now I have defined macros {TOP_1} and {LIMIT_1} and a typical query look like this:
SELECT {TOP_1} ID FROM SOME_TABLE {LIMIT_1}
Where {TOP_1} is defined for SQL Server and {LIMIT_1} is defined for PostgreSQL.
This isn't very clever for TOP 5 or LIMIT 10 though...
Is there a clever way to do it?
Thanks in advance,
Regards, Paul.