mysql_thumbnail

Show only one record or row in MySQL, SQL 2005, SQL 2008, PostgreSQL

The answer for this question is very simple if you already have experience in multiple SQL Servers such as MySQL, MS SQL 2005, PostgreSQL etc., But, if you have knowledge in any one of the SQL engine and not experienced other SQL servers you may find difficult to get one record from a table.

Today in this post I’m going to show you how to show only one record or row from a table in all of these three SQL servers.

Lets start with the Popular MySQL Sever.

MySQL Server:

In MySQL server, LIMIT is the clause used to limit the number of records has to be shown in the result. for eg.,

the above SQL query will return the first record in the table.

If you want to use the LIMIT clause with a WHERE clause, you may have to write like below:

 


MS SQL (SQL 2005 & SQL 2008):

In MS SQL Server it is entirely different, because, Microsoft SQL does not have a clause called LIMIT instead it is TOP, also the SQL query is entirely different from the MySQL query.

To limit the number of records in SQL 2005 or SQL 2008, write this one:

Obviously, the above MS SQL query will return the first row of the table. 

So if you wish to use TOP and WHERE clause in MS SQL follow this:

 

PostgreSQL:

To show the first row from a table in PostgreSQL, the query is same like MySQL:

 

using WHERE clause and LIMIT in PostgreSQL is also same like MySQL:

 

Enjoy the Day!

Leave a Reply