SELECT with WHERE clause tutorial
SELECT column1, column2, column3... FROM table_name;
For Rename Column:
For Example: Column name is id, name, age, gender, phone, city and we have to change column name to ID, Name, Age, Gender, Phone, City in table name "personal" then we can change as shown below Sql command:
SELECT id AS ID, name AS Name, age AS Age, gender AS Gender, phone AS Phone, city AS City FROM personal;
For add Space between two words in Column Name by Renaming Column name:
For Example: Column name is Student and we have to change column name to "Student Name" then we can change as shown below Sql command:
SELECT id AS ID, name AS "Student Name", age AS Age, gender AS Gender, phone AS Phone, city AS City FROM personal;
SELECT with WHERE Clause Syntax:
SELECT column1, column2, column3... FROM table_name WHERE condition;
WHERE Comparison Operators as shown below :
= Equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
<> Or != Not equal
BETWEEN Between a certain range
LIKE Search for a pattern
IN To specify multiple possible values for a column
If we want to select any particular record from database, For Example : Select "gender" and "city" column from table "personal" and gender must be Female then we can use below Sql command as shown below :
SELECT gender, city FROM personal WHERE gender = "F";
If we want to select records from table "personal" whose age Less than 20 then we can use below Sql command as shown below :
SELECT * FROM personal WHERE age < 20;
If we want to select records from table "personal" whose city is not equal to "Agra" then we can use below command as shown below :
SELECT * FROM personal WHERE city != "Agra";
If we want to select any particular column record from table "personal" For Example: Select "id" and "age" column from table "personal" and condition is that city is not equal to "Agra" then we can use below Sql command as shown below :
SELECT id, age FROM personal WHERE city != "Agra";
Comments
Post a Comment