Select in MySQL
Previous Home Next

The most commonly used command in mysql is SELECT statement. It is used to retrieve the selected data according to the conditions specified. In simple words, we can say that the select statement used to query or retrieve data from a table in the database. Here is the syntax of select statement.

SELECT expressions
FROM tables
WHERE conditions;

There are some optional clause in the Select statement, they are define as follows:

  1. where: It gives the specific conditions.
  2. Group by: It gives the aggregate function applied at each group.
  3. Order by: It gives the output according to the order specified.
  4. Having by: It gives the output among the groups defined by the GROUP BY clause.

Here i have shown some examples of the Select statement.

i have use a table name studinfo From the database school whose view as given below:

basic Select Query is given below

SELECT * 		//'*' uses to show all value
FROM studinfo;		//studinfo is a tablename

After execute this query we got the result as image given below

Output become

Note: use asterisk (*) to display all the data from a selected table

Now if we want some selected columns like fname and lname so we can use the below code

SELECT sid, fname, lname  	//select fname and lname 
FROM studinfo;			//studinfo ia a tablename

Output become

use another condition where full syntax of Select can be use


SELECT * 			//show all the value
FROM studinfo			//studinfo is tablename
WHERE sid > 106;		//conditions given here > 0

Output become

use some optional clause in the select statement


SELECT * 			//show all the value
FROM studinfo 			//studinfo is tablename
ORDER BY fname;			//order condistion write here

Output become


SELECT fname 			//show only fname
AS Name 			//show heading as column Name
FROM studinfo;			//studinfo is tablename

Output become

In the above code AS can be use to given output columnname, like Name.

Previous Home Next