Different type of select query in SQL

Different type of select query in SQL

SELECT is most commonly used statement in SQL to retrieve a data from database using different types of select queries. The SELECT statement is used for select the data from one or more tables into the database. We can select one or more column or all the column using SELECT statement. The below statement is used to retrieve data from database using SELECT statement.


1.    Retrieve all column from the table
SELECT * FROM table_name;
2.    Retrieve particular column from the table
SELECT column_name, column_name_2 FROM table_name;
3.    Retrieve data using where condition
SELECT * FROM table_name WHERE column_name=’value’;
4.    Retrieve random data from the table
SELECT *FROM table_name ORDER BY RAND();
5.    Retrieve random data with limitation of rows
SELECT * FROM table_name ORDER BY RAND() LIMIT 10;

Here, it will display only 10 number of rows randomly from the database table.

6.    Retrieve data using date in descending order from the table
SELECT * FROM table_name ORDER by date DESC;

Here, it will display all the data by sorting date in descending order

7.    Retrieve data using date in ascending order from the table
SELECT * FROM table_name ORDER by date ASC;

Here, it will display all the data by sorting date in descending order

8.    Retrieve data using string value in descending order
SELECT * FROM table_name ORDER BY country DESC;
9.    Retrieve data using string value in ascending order
SELECT * FROM table_name ORDER BY country ASC;
10.    Retrieve data using LIKE operator
SELECT column_name FROM table_name WHERE column LIKE '%$pattern%';
Here, the LIKE operator is used in WHERE clause to search specific pattern from the column of the database table.

This all above statements are commonly use statements for retrieving data from the database table. It is very useful an easy statement to apply into your project.

If you want to more about SQL statement then write comment into the comment box and don’t miss to share with your friends to help them.





Also Read:

The Indian government took an unprecedented step and decided to ban 59 Chinese apps

Post Comments(0)

Leave a reply