SQL SELECT TOP Clause

SELECT TOP clause is used to select the top records form a table.

Basic Syntax

<?php  

	SELECT column_name(s)
	FROM table_name
	WHERE condition
	LIMIT number;

?>

Example

Note: we can use all the three below methods for the same example.

Where we want to select top 3 customers from a customers table.

<?php  

    SELECT TOP 3 * FROM Customers; 

?>


It works same like the above using LIMIT Clause

<?php  

    SELECT * FROM Customers
	LIMIT 3; 

?>


It works same like the above using ROWNUM

<?php  

    SELECT * FROM Customers
	WHERE ROWNUM <= 3;  

?>


If we want to select top records with a specific condition or place

<?php  

    SELECT * FROM Customers
	WHERE Country='Germany'
	LIMIT 3;

?>