The SQL SELECT Statement
The SELECT statement is used to select data from a database.SQL SELECT Syntax
SELECT column_name,column_name
FROM table_name;
FROM table_name;
Ex.
SELECT * FROM TABLE_NAME
Note - This Query select All data in table from database.
The DISTINCT keyword can be used to return only distinct (different) values.
The following SQL statement selects only the distinct values from the "Name" columns from the "Master" table:
SQL SELECT DISTINCT
The SELECT DISTINCT statement is used to return only distinct (different) values.
In a table contain many duplicate values. and sometimes you only want to list the different (distinct) values.The DISTINCT keyword can be used to return only distinct (different) values.
SQL SELECT DISTINCT Syntax
SELECT DISTINCT column_name
FROM table_name
Example
SELECT DISTINCT Name FROM Master;
The SQL WHERE
In Sql Select Query you want to apply Where condition then use this query and give condition whatever you want to apply. like example
Syntax
SELECT column1,column2 FROM TableName WHERE column_name operator value;Example
Select EmpName,Salary from Employe
EmpName | Salary |
Jeet | 30000 |
Ranu | 15000 |
Pulkit | 10000 |
Vijay | 12000 |
Note - In This Select query select EmpName & Salary column name from Employe table ,execute this query then get all EmpName and according salary in Employe table, but You want those record according particular Empname and salary based then you apply where condition. like
Example
Select EmpName,Salary from Employe where Salary > 15000
Output-
Note- Filter according where condition and get result
Output-
Note- Filter according where condition and get result
EmpName | Salary |
Jeet | 30000 |
SQL ORDER BY
Select Query and you want to sort result by one or more columns then use order by in query like in exampleSyntax
SELECT column1,column2 FROM TableName ORDRE BY column_name ASC|DESCExample
SELECT EmpName,Salary from Employe ORDER BY EmpName DESC
EmpName | Salary |
Vijay | 12000 |
Ranu | 15000 |
Pulkit | 10000 |
Jeet | 30000 |
SQL AND & OR Operators
In this artical describe The AND & OR operators. This operators are used to filter records based on more than one condition. AND Operator- Apply this Operator displays a record if both the first condition AND the second condition are true.Both condition are mandatory true
Syntax
SELECT column1,column2 FROM TableName WHERE Condition1 AND condition2Example
Select EmpName,Salary from Employe where Salary > 15000
AND Salary = 30000
Output-
Note- Filter according where condition and get result
Output-
Note- Filter according where condition and get result
EmpName | Salary |
Jeet | 30000 |
OR Operator
OR Operator- Apply this Operator displays a record if either the first condition AND the second condition is true.
Example
Select EmpName,Salary from Employe where Salary > 15000
OR Salary < 40000
Output-
Note- Filter according where condition and get result
Output-
Note- Filter according where condition and get result
EmpName | Salary |
Jeet | 30000 |
Combining AND & OR
You can also combine AND and OR (use parenthesis to form complex expressions).
Example
Select EmpName,Salary from Employe where EmpName='Jeet' AND (Salary > 15000
OR Salary < 40000)
Output-
Note- Filter according where condition and get result
Output-
Note- Filter according where condition and get result
EmpName | Salary |
Jeet | 30000 |
0 comments :
Post a Comment