2 D
2 D
SYLLABUS
Attributes
Relation name
EMPLOYEE
EMP_NO Name Address Mobile number Age Salary
Tuples 101 RAM XYZ 9898989898 20 10000
102 SAM CVF 9999999999 21 20000
103 SITA FDFD 888888888 22 30000
4
•In the relational model, all data is logically structured within relations (also called table)
•Informally a relation may be viewed as a named two- dimensional
table representing an entity set.
•A relation has a fixed number of named columns and variable number of rows.
Components of relational database
Data type
Format
dom(Cust-name) is varchar(25)
•The role these strings play in the CUSTOMER relation is that of the name of a
customer.
15 •A relation state r(R) is a mathematical relation of degree n on the domains dom(A1),
dom(A2)…, dom(An) which is a subset of Cartesian product(X) of domains that define
R
•
Alternative Definition of a Relation
•Formally,
Given R(A1, A2, .........., An)
r(R) ⊂ dom (A1) X dom (A2) X ....X dom(An)
•R(A1, A2, …, An) is the schema of the relation
•R is the name of the relation
•A1, A2, …, An are the attributes of the relation
•r(R): a specific state (or "value" or “population”) of relation R –
this is a set of tuples (rows)
(However, a more general alternative definition of relation does not require this ordering).
•Values in a tuple:
24
All values are considered atomic (indivisible).
Each value in a tuple must be from the domain of the attribute for that column
If tuple t = <v1, v2, …, vn> is a tuple (row) in the relation state r of R(A1, A2, …,
A special null value is used to represent values that are unknown or inapplicable to certain
tuples.
•Notation:
•Constraints are conditions that must hold on all valid relation states.
•There are three main types of constraints in the relational model:
✔ Key constraints
✔ Entity integrity constraints
✔ Referential integrity constraints
•Another implicit constraint is the domain constraint
Every value in a tuple must be from the domain of its attribute (or it could be null,
if allowed for that attribute)
Types of keys:
Primary key
Key used to identify one and only one instance of an entity uniquely.
An entity can contain multiple keys, as we saw in the PERSON
table.
The key which is most suitable from those lists becomes a primary key.
EMPLOYEE table, ID can be the primary key since it is unique for each employee.
In the EMPLOYEE table, we can even select License_Number and
Passport_Number as primary keys since they are also unique.
Candidate key
•A candidate key is an attribute or set of attributes that can uniquely identify a tuple.
•Except for the primary key, the remaining attributes are considered a candidate key.
•The candidate keys are as strong as the primary key.
Eg. EMPLOYEE table, id is best suited for the primary key. The rest of the attributes, like
SSN, Passport_Number, License_Number, etc., are considered a candidate key.
Super key
Artificial key
The key created using arbitrarily assigned data are known as artificial keys.
These keys are created when a primary key is large and complex and has no
relationship with many other relations.
The data values of the artificial keys are usually numbered in a serial order.
Key Constraints
•Super key of R:
Is a set of attributes SK of R with the following condition:
No two tuples in any valid relation state r(R) will have the same value for
SK That is, for any distinct tuples t1 and t2 in r(R), t1[SK] ≠ t2[SK]
• Key of R:
✔ A "minimal" super key
✔ That is, a key is a super key K such that removal of any attribute from K results
in a set of attributes that is not a super key (does not possess the superkey
uniqueness property)
Entity Integrity
The primary key attributes PK of each relation schema R in S cannot have null
values in any tuple of r(R).
✔ This is because primary key values are used to identify the individual tuples.
✔ t[PK] ≠ null for any tuple t in r(R)
✔ If PK has several attributes, null is not allowed in any of these attributes
Note: Other attributes of R may be constrained to disallow null values, even though
they are not members of the primary key.
Referential Integrity
attributes) that reference the primary key attributes PK of the referenced relation
R2.
(2) a null.
•In case (2), the FK in R1 should not be a part of its own primary key.
Relational Database Schema
A set S of relation schemas that belong to the same
database. S is the name of the whole database schema
Constraints
•Each relation schema can be displayed as a row of attribute names
•The name of the relation is written above the attribute names
•The primary key attribute (or attributes) will be underlined
•A foreign key (referential integrity) constraints is displayed as a directed arc (arrow)
from the foreign key attributes to the referenced table
Can also point the primary key of the referenced relation for clarity
Populated database state
•Each relation will have many tuples in its current relation state
•The relational database state is a union of all the individual relation states
•Whenever the database is changed, a new state arises
•Basic operations for changing the database:
INSERT a new tuple in a relation
DELETE an existing tuple from a relation
MODIFY an attribute of an existing tuple
40
Update Operations on Relations
1. INSERT a tuple.
2. DELETE a tuple.
3. MODIFY a tuple.
• Integrity constraints should not be violated by the update operations.
•Several update operations may have to be grouped together.
•Updates may propagate to cause other updatesautomatically.
• This may be necessary to maintain integrity constraints.
42
• Domain constraint:
•if one of the attribute values provided for the new tuple is not of the specified
attribute domain
• Key constraint:
•if the value of a key attribute in the new tuple already exists in another tuple in the relatio
• Referential integrity:
•if a foreign key value in the new tuple references a primary key value that does not
exist i the referenced relation
• Entity integrity: if the primary key value is null in the new tuple
44
SET NULL option: set the foreign keys of the referencingtuples to NULL
One of the above options must be specified during database design for each foreign
key constraint
45 •UPDATE may violate domain constraint and NOT NULL constraint on an attribute being
modified
•Any of the other constraints may also be violated, depending on the attribute being updated:
Updating the primary key (PK):
Similar to a DELETE followed by an
INSERT Need to specify similar options to
DELETE
Person_id
DoB
Person
Name Gender
•The initial relational schema is expressed in the following format writing the table names with
the attributes list inside a parentheses as shown below for
PePrNO
H O
s o Phone Phone
-1 -2
Person_id nN_Ei-d
DoB Person_id
Phone
Person
Name Gender
•If you have a multi-valued attribute, take the attribute and turn it into a new entity or table
of its own.
•Then make a 1: N relationship between the new entity and the existing one.
•Create a table for the attribute.
Add the primary (id) column of the parent entity as a foreign key within the new
table PERSONS( personid , name, dateOfBirth, gender)
PERSONS_PHONE(personid ,phone)
personid within the table Phones is a foreign key referring to the personid of Persons
1: 1 Relationship
PHONE
-NO DoB Wife_id
Person_id
Gender
•For cases when the Person is not married i.e. has no wifeID, the attribute can set
to NULL
PERSONS( personid , name, dateOfBirth, gender,wifeid)
•For instance, the Person can have a House from zero to many , but a House
can be owned by only one Person.
•To represent such relationship the personid asthe Parent node must be
placed within the Child table as a foreign key
PERSONS( personid , name, dateOfBirth, gender)
PERSONS_PHONE(personid ,phone)
HOUSE(houseid, personid, number, address)
M:N Relationships
Weak
Entity
CAR(Car_ID,
Serial_Number,Model_Number,Color,Year,Customer_ID,Emp_ID)
CUSTOMER(Customer_ID,Name, PhoneNumber, Address, Country,
City)
EMPLOYEE(Emp_ID, Name, Address)
EMPLOYEE_QUALIFICATION(Emp_ID,Qualification
) INVOICE(Invoice_ID,Date,Emp_ID,Customer_ID)
55
56
EMPLOYEE(Emp_ID, First_Name,Last_Name,DOB,Company_Id,Project_Id)
EMPLOYEE_CONTACT_NUMBER(Emp_ID,Contact_Number)
COMPANY(Company_Id,Company_Name,Location)
PROJECT(Project_Id,Project_Name,Start_Date)
SALARY(EMP_Id,Amount,Date_Of_Salary,Mode_of_Payment)
•select
• project
•cartesian product operations
•join - Equi-join
•natural join
•query examples
57
58
•It uses operators to perform queries. An operator can be either unary or binary.
•They accept relations as their input and yield relations as their output.
•Relational algebra is performed recursively on a relation and intermediate results are also
considered relations.
59
•The basic set of operations for the relational model is the relational algebra.
•These operations enable a user to specify basic retrieval requests as
relational algebra expressions.
•The result of a retrieval is a new relation, which may havebeen formed from one or
more relations.
•The algebra operations thus produce new relations, which can be further manipulated
using operations of the same algebra.
•A sequence of relational algebra operations forms a relational algebra expression,
whose result will also be a relation that represents the result of a database query
60
61
1. SELECT
2. PROJECT
3. RENAME
The SELECT Operation
•The SELECT operation is used to choose a subset of the tuples from a relation that
satisfies a selection condition.
•SELECT operation restricts the tuples in a relation to
tuples thatsatisfy the
only those condition
The relation resulting from the SELECT operation has the same attributes as R.
•The Boolean expression specified in <selection condition> is made up of a number of
clauses of the form
•Clauses can be connected by the standard Boolean operators and, or, and not to form a
general selection condition.
63
Select the tuples for all employees who either work in department 4 and
make over $25,000 per year, or work in department 5 and make over $30,000,
σ(Dno=4 AND Salary>25000) OR (Dno=5 AND Salary>30000) (EMPLOYEE)
64
• |σ c (R) |<= | R|
σc1 (σc2 (. . . (σcn (R)))) = σc1 AND c2 AND ... AND cn (R)
68
•PROJECT operation selects certain columns from the table and discards the other columns.
•If we are interested in only certain attributes of a relation, we use the PROJECT operation to project
the relation over these attributes only
•Example: list each employee’s first and last name and salary
πName, Age(Student) π
ID, Name(Student)
70
•For most queries, we need to apply several relational algebra operations one after the
other.
Either we can write the operations as a single relational algebra expression by
nesting the operations, or
we can apply one operation at a time and create intermediate result
relations we must give names to the relations that hold the intermediate
results.
75
Retrieve the first name, last name, and salary of all employees who work in
department number 5
we must apply a SELECT and a PROJECT operation
•The results of the operations that we are performing are saved without any name.
•If we want to give some name to the result of any operation then we
can rename the
result of the operations using the rename operation.
•If no renaming is applied, the names of the attributes in the resulting relation of a
SELECT operation are the same as those in the original relation and in the same
order.
•PROJECT operation with no renaming, the resulting relation has the same attribute
names as those in the projection list and in the same order in which they appear in the
list.
79
only.
80
•UNION:
✔ The result of this operation, denoted by R 𝖴 S, is a relation that includes all tuples that are
either in R or in S or in both R and S.
•Two relations R(A1, A2, ..., An) and S(B1, B2, ..., Bn) are said to be union compatible
(or type compatible)
if they have the same degree n and if dom(Ai) = dom(Bi) for 1 <=i<=n.
This means that the tworelations have the same number of attributes
and each
corresponding pair of attributes has the same domain.
82
(a)T
.
∩
83
(d)STUDENT − INSTRUCTOR
( e)INSTRUCTOR −
STUDENT
84
•Retrieve the Social Security numbers of all employees who either work in department 5
or directly supervise an employee who works in department 5, we can use the UNION
operation as follows
•UNION operation produces the tuples that are in either RESULT1 or RESULT2
or both, while eliminating any duplicates.
85
πSuper_ssn(DEP5_EMPS) RESULT ←
RESULT1 ∪ RESULT2
86
•Result of R(A1, A2, ..., An) × S(B1, B2, ..., Bm) is a relation Q with degree n + m
attributes Q(A1, A2, ..., An, B1, B2, ..., Bm), in that order.
•The resulting relation Q has one tuple for each combination oftuples—one from R
and one from S.
•Hence, if R has nR tuples (denoted as |R| = nR), and S has nS tuples, then R × S
will have nR * nS tuples.
•Produces new tuples by concatenating all possible combinations of tuples from n
underlying relations
88
89
90
FEMALE_EMPS ← σ Sex=‘F’(EMPLOYEE)
EMPNAMES ← π Fname, Lname,
Ssn
(FEMALE_EMPS)
91
92
ACTUAL_DEPENDENTS ← σSsn=Essn(EMP_DEPENDENTS)
•The CARTESIAN PRODUCT creates tuples with the combined attributes of two relations.
•We can SELECT related tuples only from the two relations by specifying an appropriate
selection condition after the Cartesian product, as we did in the preceding example.
•Because this sequence of CARTESIAN PRODUCT followed by SELECT is quite commonly
used to combine related tuples from two relations, a special operation, called JOIN, was
created to specify this sequence as a single operation
94
•The JOIN operation, denoted by , is used to combine related tuples from two relations into
single “longer” tuples.
•This operation is very important for any relational database with more than a single relation
because it allows us to process relationships among relations.
RESULT
Dname Lname Fname
Research Wong Franklin
Administration Wallance Jennifer
Headquaters Borg James
96
•The JOIN operation can be specified as a PRODUCT
CARTESIAN followed by a SELECT operation. operation
•These two operations can be replaced with a single JOIN operation as follows
97
•JOIN operation on two relations R(A1, A2, ..., An) and S(B1, B2, ..., Bm) is
•The result of the JOIN is a relation Q with n + m attributes Q(A1, A2, ..., An, B1, B2,
... , Bm) in that order;
•Q has onetuple for each combination of tuples—one from R andonefrom
S— whenever the combination satisfies thejoin condition
98
•In JOIN, only combinations of tuples satisfying the join condition appear in the
result, whereas in the CARTESIAN PRODUCT all combinations of tuples are
included in the result.
•The join condition is specified on attributes from the two relations R and S and is
evaluated for each combination of tuples.
•Each tuple combination for which the join condition evaluates to TRUE is included in
the resulting relation Q as a single combined tuple.
107 Different Types of SQL
JOINs
•INNER JOIN
Returns records that have matching values in both tables
1. Theta join
2. EQUI join
3. Natural join
• OUTER JOIN
In an outer join, along with tuples that satisfy the matching criteria, we also include
some or all tuples that do not match the criteria.
< condition > AND < condition > AND… AND < condition
>
where each <condition> is of the form Ai θ Bj,
Ai is an attribute of
R, Bj is an attribute of
S,
•denoted by
*,
• NATURAL JOIN requires that the two join attributes (or each pair of join attributes) have
the same name in both relations.
•If this is not the case, a renaming operation is applied first.
101
Project
Pname Pnumber Rocation Dnum Dname Mgr_ssn Mgr_sta1
ProductX 1 Bellaire 5 Research 333445555 1988-05-!
ProductY 2 Sugaland 5 Reseach 333445555 1988-05-!
ProductZ 3 Houston 5 Reseach 333445555 1988-05-!
Computerizati 10 Stafford 4 Administration 987654321 1995-01-1
o n
Reorganization 20 Houston 1 Headquartem 888665555 1981-06-‘
Newbenefits 30 Stafford 4 Administration 987654321 1995-01-1
Dept
Dname Dnumber Mgr_ssn Mgr_start_date Location
Head-quarters 1 888665555 1981-06-19 Houston
Administration 4 987654321 1995-01-01 Stafiord
Research 5 333445555 1988-05-22 Bellaire
Research 5 333445555 1988-05-22 Sugarland
Research 5 333445555 1988-05-22 Houston
102
Combine each PROJECT tuple with the DEPARTMENT tuple that controls the project
First we rename the Dnumber attribute of DEPARTMENT to Dnum
so thatit has the same name as the Dnum attribute in PROJECT andthen we
apply NATURAL JOIN
PROJ_DEPT ← PROJECT * ρ
(Dname, Dnum, Mgr_ssn, Mgr_start_date)(DEPARTMENT)
•The same query can be done in two steps by creating an intermediate table
DEPT
DEPT ← ρ
(Dname, Dnum, Mgr_ssn, Mgr_start_date)(DEPARTMENT)
In the PROJ_DEPT relation, each tuple combines a PROJECT tuple with the
DEPARTMENT tuple for the department that controls the project, but only one join
attribute value is kept.
104
•If the attributes on which the natural join is specified already have the same names in
both relations, renaming is unnecessary
•to apply a natural join on the Dnumber attributes of DEPARTMENT
and DEPT_LOCATIONS
•Join condition for NATURAL JOIN is constructed by equating each pair of join
attributes that have the same name in the two relations and combining these
conditions with AND.
•There can be a list of join attributes from each relation, and each corresponding pair
must have the same name.
► In Inner Join, the matched rows are returned and unmatched rows are not returned.
► But, in outer join, we include those tuples which meet the given condition along with that,
we also add those tuples which do not meet the required condition.
► The result also includes the tuples from the left and right tables which do not satisfy the
conditions.
► Based on the tuples that are added from left, right or both the tables, the outer join is
further divided into three types.
► Note: The operators here define the existence of null value which we will use to fill the
table if the required conditions do not match.
109
► Left Outer Join is a type of join in which all the tuples from left relation are included and
only those tuples from right relation are included which have a common value in the
common attribute on which the join is being performed.
► Right Outer Join is a type of join in which all the tuples from right relation are
included and only those tuples from left relation are included which have a
common value in the common attribute on which the right join is being
performed.
► Student ⟖ Course
113
► Full Outer Join is a type of join in which all the tuples from the left and right relation which
are having the same value on the common attribute. Also, they will have all the remaining
tuples which are not common on in both the relations.
► List the name of students who are older than 30 and who are not studying CS
πStName(σAge>30(STUDENTS)) − πStName(σMajor=’CS’(STUDENTS))
► Rename AName in the relation AUTHORS to Name
ρAName/Name(AUTHORS)
117
► Assume the following relations:
BOOKS(DocId, Title, Publisher, Year)
STUDENTS(StId, StName, Major,
Age) AUTHORS(AName, Address)
borrows(DocId, StId, Date)
has-written(DocId,
AName) describes(DocId,
Keyword)
1. List each book with its keywords.
2. List each student with the books she/he has borrowed.
3. List the title of books written by the author ’Ullman’
4. List the authors of the books the student ’Smith’ has borrowed
5. Which books have both keywords ’database’ and
’programming’?
118
► Write relation algebra expression to get the details of salespersons who have
travelled between Mumbai and Delhi and the travel expense is greater that Rs.
50000.
1. Give the details (all attributes of TRIP) for trips which exceeded $2000 in expenses.
3. Print the trip expenses incurred through the salesman with SSN= ‘234-56-7890'.
122 Assume
► the following relations:
SALESPERSON(Ssn, Name, StartYear, DeptNo)
TRIP(Ssn, FromCity, ToCity, DepartureDate, ReturnDate,
TripId) EXPENSE(TripId, AccountNo, Amount)
1. Give the details (all attributes of TRIP) for trips which exceeded $2000 in expenses.
3. Print the trip expenses incurred through the salesman with SSN= ‘234-56-7890'.
A: πAmount(σSsn=‘234-56-7890'(TRIP ⋈ EXPENSE))
123
1. Retrieve the name and address of all employees who work for the ‘Research’
department.
2. For every project located in ‘Stafford’, list the project number, the controlling
department number, and the department manager’s last name, address, and birth
date.
124
3. Make a list of project numbers for projects that involve an employee whose last name is
‘Smith’, either as a worker or as a manager of the department that controls the project.
Introduction to Structured Query Language (SQL)
Data Definition Language (DDL)
Table definitions and operations –
CREATE, DROP, ALTER, INSERT, DELETE,
UPDATE.
125
126
► Structured Query Language(SQL) was developed at IBM by Donald D. Chamberlin and
relational database.
► The SQL data-definition language (DDL) allows the specification of information about
relations, including:
► Integrity constraints
128
► real, double precision. Floating point and double-precision floating point numbers,
with machine-dependent precision.
► It simply deals with descriptions of the database schema and is used to create and modify
the structure of database objects in the database.
► CREATE DATABASE
► CREATE TABLE
133
► A Database is defined as a structured set of data. So, in SQL the very first step to store the
data in a well structured manner is to create a database.
► Syntax:
► Example
► Domain Constraints
136
► not null
► Specifies that the null value is not allowed for that attribute
137
138
► create table instructor (
ID char(5),
name varchar(20) not null,
dept_name varchar(20),
salary numeric(8,2),
primary key (ID),
foreign key (dept_name) references department);
► create table student (
ID varchar(5),
name varchar(20) not null,
dept_name varchar(20),
tot_cred numeric(3,0),
primary key (ID),
foreign key (dept_name) references department);
create table takes
139
ID varchar(5),
(
course_id varchar(8),
sec_id varchar(8),
semester varchar(6),
year numeric(4,0),
grade varchar(2),
primary key (ID, course_id, sec_id, semester, year)
, foreign key (ID) references student,
foreign key (course_id, sec_id, semester, year) references
section);
► course_id
create table coursevarchar(8),
(
title varchar(50),
dept_name varchar(20),
credits numeric(2,0),
primary key (course_id),
foreign key (dept_name) references
140
► DROP is used to delete a whole database or just a table.
► The DROP statement destroys the objects like an existing database, table, index,
or view.
► The result of this operation quickly removes all data from a table
► Syntax:
► Truncate is normally ultra-fast and its ideal for deleting data from a temporary table.
► Truncate preserves the structure of the table for future use, unlike drop table where the table
is deleted with its full structure.
► Table or Database deletion using DROP statement cannot be rolled back, so it must be
142
TRUNCATE user
143
► ALTER TABLE is used to add, delete/drop or modify columns in the existing table.
► It is also used to add and drop various constraints on the existing table.
► Syntax
ADD (Columnname_1datatype,
ROLL_NO NAME
1 Ram
1 Ram
2 Abhi
3 Rahul
4 Tanu
145
1 Ram
2 Abhi
3 Rahul
4 Tanu
1 Ram
2 Abhi
3 Rahul
4 Tanu
147
► ALTER TABLE-MODIFY
► It is used to modify the existing columns in a table. Multiple columns can also be
modified at once.
ALTER TABLE
table_name
148 ✔ The SQL ALTER TABLE command is used to add, delete or modify columns in anexisting table.
✔ You would also use ALTER TABLE command to add and drop various constraints on an existing table.
✔ The basic syntax of ALTER TABLE to add a new column in an existing table is as follows:
The basic syntax of ALTER TABLE to change the DATA TYPE of a column in a table is as follows:
The basic syntax of ALTER TABLE to ADD PRIMARY KEY constraint to a table is as
follows:
follows:
► For this purpose we can use ALTER TABLE to rename the name of table.
► Syntax(Oracle,MySQL,MariaDB):
► RENAME TO new_table_name;
► Columns can be also be given new name with the use of ALTER TABLE.
► Syntax(MySQL, Oracle):
151
► It is a language used for selecting, inserting, deleting and updating data in a database.
► INSERT
► UPDATE
► DELETE
152
2. Data Manipulation Language (DML)
It provides a set of operations to support the basic data manipulation
operations on the data held in the database.
It is used to query, update or retrieve data stored in a
database.
► Syntax :
► INSERT INTO table_name (column1, column2, column3, ...) VALUES
► If you are adding values for all the columns of the table, you do not need to
specify the column names in the SQL query.
► Make sure that the order of the values is in the same order as the columns in the
table.
154
► Syntax
in database.
► Syntax
UPDATE table_name
WHERE condition;
► Note: The WHERE clause specifies which record(s) that should be updated. If you omit
the WHERE clause, all records in the table will be updated!
158
UPDATE Customers
SET ContactName = 'Alfred Schmidt', City=
'Frankfurt' WHERE CustomerID = 1;
159
UPDATE Customers
SET ContactName = 'Alfred Schmidt', City=
'Frankfurt' WHERE CustomerID = 1;
UPDATE Customers
SET ContactName='Juan'
WHERE Country='Mexico';
CustomerID CustomerName ContactName Address City PostalCode Country
Alfreds
1 Alfred Schmidt Obere Str. 57 Frankfurt 12209 Germany
Futterkiste
Ana Trujillo
Avda. de la
2 Emparedados y Juan México D.F. 05021 Mexico
Constitución 2222
helados
Antonio Moreno
3 Juan Mataderos 2312 México D.F. 05023 Mexico
Taquería
4 Around the Horn Thomas Hardy 120 Hanover Sq. London WA1 1DP UK
Berglunds
5 Christina Berglund Berguvsvägen 8 Luleå S-958 22 Sweden
snabbköp
161
UPDATE Customers
SET ContactName='Juan';
CustomerID CustomerName ContactName Address City PostalCode Country
Alfreds
1 Juan Obere Str. 57 Frankfurt 12209 Germany
Futterkiste
Ana Trujillo
Avda. de la
2 Emparedados y Juan México D.F. 05021 Mexico
Constitución 2222
helados
Antonio Moreno
3 Juan Mataderos 2312 México D.F. 05023 Mexico
Taquería
4 Around the Horn Juan 120 Hanover Sq. London WA1 1DP UK
Berglunds
5 Juan Berguvsvägen 8 Luleå S-958 22 Sweden
snabbköp
162
► The DELETE Statement in SQL is used to delete existing records from a table.
► We can delete a single record or multiple records depending on the condition
we specify in the WHERE clause.
► Syntax
► Syntax
► Example
✔ SQL SELECT statement is used to fetch the data from a database table which returns data in
the form of result table. These result tables are called result-sets.
✔ Syntax:
✔ The basic syntax of SELECT statement is as follows:
SELECT column1, column2, columnN FROM table_name;
✔ Here, column1, column2...are the fields of a table whose values you want to fetch.
✔ If you want to fetch all the fields available in the field, then you can use the following syntax:
Syntax
Category
SELECT DISTINCT category
Gadgets
FROM Product
Photography
Household
Compare to:
Category
SELECT Gadgets
Photography
Product
Household
169