How to select just the top row from a database
Monday, July 10th, 2006
Once upon a time I needed to select just the top row from a database, this was actually so I could get the names of the columns that were defined in the table. I had my reasons, okay! Well, I’ve found a better way than doing it this way now (after all, this won’t work on an empty table), but that’s another post. So, to select the first row from an sql database, you can do either of these. The first works in MS Access, the second in PostgreSQL.
SELECT TOP 1 * FROM table;
SELECT * FROM "table" LIMIT 1;
Simple, eh? The second probably works in MySQL too, but I’ve not tried it.