Professional Documents
Culture Documents
SQL Commands 8
SQL Commands 8
SQL Commands 8
Nahida Nazir
Select distict
Nahida Nazir
Nahida Nazir
create table j (id int, name varchar(21));
insert into j values (21, 'raj')
insert into j values (21, 'piya')
insert into j values (22, 'rohan')
select distinct id from j
Nahida Nazir
NULL Value
A field with a NULL value is a field with no value.
If a field in a table is optional, it is possible to insert a
new record or update a record without adding a value to
this field. Then, the field will be saved with a NULL value.
Nahida Nazir
Syntax
SELECT column_names
FROM table_name
WHERE column_name IS NULL;
Nahida Nazir
IS NOT NULL Syntax
SELECT column_names
FROM table_name
WHERE column_name IS NOT NULL;
Nahida Nazir
The IS NULL Operator
Nahida Nazir
IS NOT NULL operator
Nahida Nazir
SELECT id, name
FROM j
WHERE id IS NULL;
Nahida Nazir
Adding 100 to an existing id
Nahida Nazir
SELECT id, name, id - 100
AS "id - 100" FROM ji;
Nahida Nazir
Multiplication
Nahida Nazir
SQL AND and OR operators
In SQL, the AND & OR operators are used for filtering the data and getting
precise results based on conditions. The SQL AND & OR operators are also used
to combine multiple conditions. These two operators can be combined to test for
multiple conditions in a SELECT, INSERT, UPDATE, or DELETE statement.
The AND and OR operators are used with the WHERE clause.
These two operators are called conjunctive operators.
AND Operator:
Nahida Nazir
AND Operator:
This operator displays only those records where both the conditions
condition1 and condition2 evaluates to True.
Syntax:
Nahida Nazir
Example
Nahida Nazir
OR Operator:
This operator displays the records where either one of the conditions
condition1 and condition2 evaluates to True. That is, either condition1 is True
or condition2 is True
To fetch all the records from the Student table where NAME is Ram or NAME
is SUJIT.
SELECT * FROM Student WHERE NAME = ‘piya' OR NAME = ‘rahul';
Nahida Nazir
Take an example to fetch all the records from the Student table
where Age is 18 NAME is Ram or RAMESH.
SELECT * FROM Student WHERE Age = 18 AND (NAME = 'Ram' OR
NAME = 'RAMESH');
Nahida Nazir
Not operator
Nahida Nazir
To get the employees who work in the department id 5 and with a salary not
greater than 5000.
SELECT
id,
name,
salary
FROM
employees
WHERE
id = 5
AND NOT salary > 5000
ORDER BY
salary;
Nahida Nazir