Docsity

**Title:** **Complete Database Management System (DBMS) Notes – SQL, ER Model, Normalizati, Lecture notes of Database Management Systems (DBMS)

Toggle sidebar
bg1
LEC-1: Introduction to DBMS
1. What is Data?
a. Data is a collection of raw, unorganized facts and details like text, observations, figures, symbols,
and descriptions of things etc.
In other words, data does not carry any specific purpose and has no significance by itself.
Moreover, data is measured in terms of bits and bytes – which are basic units of information in the
context of computer storage and processing.
b. Data can be recorded and doesn’t have any meaning unless processed.
2. Types of Data
a. Quantitative
i. Numerical form
ii. Weight, volume, cost of an item.
b. Qualitative
i. Descriptive, but not numerical.
ii. Name, gender, hair color of a person.
3. What is Information?
a. Info. Is processed, organized, and structured data.
b. It provides context of the data and enables decision making.
c. Processed data that make sense to us.
d. Information is extracted from the data, by analyzing and interpreting pieces of data.
e. E.g., you have data of all the people living in your locality, its Data, when you analyze and interpret
the data and come to some conclusion that:
i. There are 100 senior citizens.
ii. The sex ratio is 1.1.
iii. Newborn babies are 100.
These are information.
4. Data vs Information
a. Data is a collection of facts, while information puts those facts into context.
b. While data is raw and unorganized, information is organized.
c. Data points are individual and sometimes unrelated. Information maps out that data to provide a
big-picture view of how it all fits together.
d. Data, on its own, is meaningless. When it’s analyzed and interpreted, it becomes meaningful
information.
e. Data does not depend on information; however, information depends on data.
f. Data typically comes in the form of graphs, numbers, figures, or statistics. Information is typically
presented through words, language, thoughts, and ideas.
g. Data isn’t sufficient for decision-making, but you can make decisions based on information.
5. What is Database?
a. Database is an electronic place/system where data is stored in a way that it can be easily accessed,
managed, and updated.
b. To make real use Data, we need Database management systems. (DBMS)
6. What is DBMS?
a. A database-management system (DBMS) is a collection of interrelated data and a set of
programs to access those data. The collection of data, usually referred to as the database,
contains information relevant to an enterprise. The primary goal of a DBMS is to provide a way to
store and retrieve database information that is both convenient and efficient.
b. A DBMS is the database itself, along with all the software and functionality. It is used to perform
different operations, like addition, access, updating, and deletion of the data.
CodeHelp
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31

Partial preview of the text

Download **Title:** **Complete Database Management System (DBMS) Notes – SQL, ER Model, Normalizati and more Lecture notes Database Management Systems (DBMS) in PDF only on Docsity!

LEC-1: Introduction to DBMS

1. What is Data? a. Data is a collection of raw, unorganized facts and details like text, observations, figures, symbols, and descriptions of things etc. In other words, data does not carry any specific purpose and has no significance by itself. Moreover, data is measured in terms of bits and bytes – which are basic units of information in the context of computer storage and processing. b. Data can be recorded and doesn’t have any meaning unless processed. 2. Types of Data a. Quantitative i. Numerical form ii. Weight, volume, cost of an item. b. Qualitative i. Descriptive, but not numerical. ii. Name, gender, hair color of a person.

  1. What is Information? a. Info. Is processed, organized, and structured data. b. It provides context of the data and enables decision making. c. Processed data that make sense to us. d. Information is extracted from the data, by analyzing and interpreting pieces of data. e. E.g., you have data of all the people living in your locality, its Data, when you analyze and interpret the data and come to some conclusion that: i. There are 100 senior citizens. ii. The sex ratio is 1.1. iii. Newborn babies are 100. These are information. 4. Data vs Information a. Data is a collection of facts, while information puts those facts into context. b. While data is raw and unorganized, information is organized. c. Data points are individual and sometimes unrelated. Information maps out that data to provide a big-picture view of how it all fits together. d. Data, on its own, is meaningless. When it’s analyzed and interpreted, it becomes meaningful information. e. Data does not depend on information; however, information depends on data. f. Data typically comes in the form of graphs, numbers, figures, or statistics. Information is typically presented through words, language, thoughts, and ideas. g. Data isn’t sufficient for decision-making , but you can make decisions based on information.
  2. What is Database? a. Database is an electronic place/system where data is stored in a way that it can be easily accessed, managed, and updated. b. To make real use Data, we need Database management systems. (DBMS)
  3. What is DBMS? a. A database-management system (DBMS) is a collection of interrelated data and a set of programs to access those data. The collection of data, usually referred to as the database , contains information relevant to an enterprise. The primary goal of a DBMS is to provide a way to store and retrieve database information that is both convenient and efficient. b. A DBMS is the database itself, along with all the software and functionality. It is used to perform different operations, like addition , access , updating , and deletion of the data.

CodeHelp

8. DBMS vs File Systems a. File-processing systems has major disadvantages. i. Data Redundancy and inconsistency ii. Difficulty in accessing data iii. Data isolation iv. Integrity problems v. Atomicity problems vi. Concurrent-access anomalies vii. Security problems b. Above 7 are also the Advantages of DBMS (answer to “ Why to use DBMS? ”)

CodeHelp

b. The overall design of the DB is called the DB schema. c. Schema is structural description of data. Schema doesn’t change frequently. Data may change frequently. d. DB schema corresponds to the variable declarations (along with type) in a program. e. We have 3 types of Schemas : Physical, Logical , several view schemas called subschemas. f. Logical schema is most important in terms of its effect on application programs, as programmers construct apps by using logical schema. g. Physical data independence , physical schema change should not affect logical schema/application programs.

3. Data Models: a. Provides a way to describe the design of a DB at logical level. b. Underlying the structure of the DB is the Data Model; a collection of conceptual tools for describing data, data relationships, data semantics & consistency constraints. c. E.g., ER model, Relational Model, object-oriented model, object-relational data model etc.

  1. Database Languages : a. Data definition language (DDL) to specify the database schema. b. Data manipulation language (DML) to express database queries and updates. c. Practically , both language features are present in a single DB language, e.g., SQL language. d. DDL i. We specify consistency constraints, which must be checked, every time DB is updated. e. DML i. Data manipulation involves 1. Retrieval of information stored in DB. 2. Insertion of new information into DB. 3. Deletion of information from the DB. 4. Updating existing information stored in DB. ii. Query language , a part of DML to specify statement requesting the retrieval of information. 5. How is Database accessed from Application programs? a. Apps (written in host languages, C/C++, Java) interacts with DB. b. E.g., Banking system’s module generating payrolls access DB by executing DML statements from the host language. c. API is provided to send DML/DDL statements to DB and retrieve the results. i. Open Database Connectivity ( ODBC ), Microsoft “C”. ii. Java Database Connectivity ( JDBC ), Java. 6. Database Administrator (DBA) a. A person who has central control of both the data and the programs that access those data. b. Functions of DBA i. Schema Definition ii. Storage structure and access methods. iii. Schema and physical organization modifications. iv. Authorization control. v. Routine maintenance
  2. Periodic backups.
  3. Security patches.
  4. Any upgrades.
  5. DBMS Application Architectures : Client machines, on which remote DB users work, and server machines on which DB system runs. a. T1 Architecture i. The client, server & DB all present on the same machine.

CodeHelp

b. T2 Architecture i. App is partitioned into 2-components. ii. Client machine, which invokes DB system functionality at server end through query language statements. iii. API standards like ODBC & JDBC are used to interact between client and server. c. T3 Architecture i. App is partitioned into 3 logical components. ii. Client machine is just a frontend and doesn’t contain any direct DB calls. iii. Client machine communicates with App server, and App server communicated with DB system to access data. iv. Business logic, what action to take at that condition is in App server itself. v. T3 architecture are best for WWW Applications. vi. Advantages :

  1. Scalability due to distributed application servers.
  2. Data integrity , App server acts as a middle layer between client and DB, which minimize the chances of data corruption.
  3. Security , client can’t directly access DB, hence it is more secure.

CodeHelp

  1. e.g., Age, loan-age, membership-period etc. 6. NULL Value
  2. An attribute takes a null value when an entity does not have a value for it.
  3. It may indicate “not applicable”, value doesn’t exist. e.g., person having no middle-name
  4. It may indicate “unknown”.
  5. Unknown can indicate missing entry, e.g., name value of a customer is NULL, means it is missing as name must have some value.
  6. Not known, salary attribute value of an employee is null, means it is not known yet. 6. Relationships
  7. Association among two or more entities.
  8. e.g., Person has vehicle, Parent has Child, Customer borrow loan etc.
  9. Strong Relationship , between two independent entities.
  10. Weak Relationship , between weak entity and its owner/strong entity.
  11. e.g., Loan Payment. 5. Degree of Relationship
  12. Number of entities participating in a relationship.
  13. Unary , Only one entity participates. e.g., Employee manages employee.
  14. Binary , two entities participates. e.g., Student takes Course.
  15. Ternary relationship, three entities participates. E.g, Employee works-on branch, employee works-on job.
  16. Binary are common. **7. Relationships Constraints
  17. Mapping Cardinality / Cardinality Ratio**
  18. Number of entities to which another entity can be associated via a relationship.
  19. One to one, Entity in A associates with at most one entity in B, where A & B are entity sets. And an entity of B is associated with at most one entity of A.
  20. E.g., Citizen has Aadhar Card.
  21. One to many, Entity in A associated with N entity in B. While entity in B is associated with at most one entity in A.
  22. e.g., Citizen has Vehicle.
  23. Many to one, Entity in A associated with at most one entity in B. While entity in B can be associated with N entity in A.
  24. e.g., Course taken by Professor.
  25. Many to many, Entity in A associated with N entity in B. While entity in B also associated with N entity in A.
  26. Customer buys product.
  27. Student attend course. 2. Participation Constraints
  28. Aka, Minimum cardinality constraint.
  29. Types , Partial & Total Participation.
  30. Partial Participation, not all entities are involved in the relationship instance.
  31. Total Participation , each entity must be involved in at least one relationship instance.
  32. e.g., Customer borrow loan, loan has total participation as it can’t exist without customer entity. And customer has partial participation.
  33. **Weak entity has total participation constraint, but strong may not have total.
  34. ER Notations**

CodeHelp

CodeHelp

LEC-7: Relational Model

  1. Relational Model (RM) organises the data in the form of relations ( tables ).
  2. A relational DB consists of collection of tables , each of which is assigned a unique name.
  3. A row in a table represents a relationship among a set of values, and table is collection of such relationships.
  4. Tuple : A single row of the table representing a single data point / a unique record.
  5. Columns : represents the attributes of the relation. Each attribute, there is a permitted value, called domain of the attribute.
  6. Relation Schema : defines the design and structure of the relation, contains the name of the relation and all the columns/attributes.
  7. Common RM based DBMS systems, aka RDBMS: Oracle, IBM, MySQL , MS Access.
  8. Degree of table: number of attributes/columns in a given table/relation.
  9. Cardinality : Total no. of tuples in a given relation.
  10. Relational Key : Set of attributes which can uniquely identify an each tuple.
  11. Important properties of a Table in Relational Model
    1. The name of relation is distinct among all other relation.
    2. The values have to be atomic. Can’t be broken down further.
    3. The name of each attribute/column must be unique.
    4. Each tuple must be unique in a table.
    5. The sequence of row and column has no significance.
    6. Tables must follow integrity constraints - it helps to maintain data consistency across the tables. 12. Relational Model Keys
    7. Super Key ( SK ): Any P&C of attributes present in a table which can uniquely identify each tuple.
    8. Candidate Key ( CK ): minimum subset of super keys, which can uniquely identify each tuple. It contains no redundant attribute. 1. CK value shouldn’t be NULL.
    9. Primary Key ( PK ):
      1. Selected out of CK set, has the least no. of attributes.
    10. Alternate Key ( AK )
      1. All CK except PK.
    11. Foreign Key ( FK )
      1. It creates relation between two tables.
      2. A relation, say r1, may include among its attributes the PK of an other relation, say r2. This attribute is called FK from r1 referencing r2.
      3. The relation r1 is aka Referencing (Child) relation of the FK dependency, and r2 is called Referenced (Parent) relation of the FK.
      4. FK helps to cross reference between two different relations.
    12. Composite Key: PK formed using at least 2 attributes.
    13. Compound Key: PK which is formed using 2 FK.
    14. Surrogate Key:
      1. Synthetic PK.
      2. Generated automatically by DB, usually an integer value.
      3. May be used as PK. 13. Integrity Constraints
    15. CRUD Operations must be done with some integrity policy so that DB is always consistent.
    16. Introduced so that we do not accidentally corrupt the DB. 3. Domain Constraints
      1. Restricts the value in the attribute of relation, specifies the Domain.
      2. Restrict the Data types of every attribute.
      3. E.g., We want to specify that the enrolment should happen for candidate birth year < 2002. 4. Entity Constraints
      4. Every relation should have PK. PK != NULL.

CodeHelp

5. Referential Constraints 1. Specified between two relations & helps maintain consistency among tuples of two relations. 2. It requires that the value appearing in specified attributes of any tuple in referencing relation also appear in the specified attributes of at least one tuple in the referenced relation. 3. If FK in referencing table refers to PK of referenced table then every value of the FK in referencing table must be NULL or available in referenced table. 4. FK must have the matching PK for its each value in the parent table or it must be NULL.

  1. Key Constraints: The six types of key constraints present in the Database management system are:-
    1. NOT NULL: This constraint will restrict the user from not having a NULL value. It ensures that every element in the database has a value.
    2. UNIQUE: It helps us to ensure that all the values consisting in a column are different from each other.
    3. DEFAULT: it is used to set the default value to the column. The default value is added to the columns if no value is specified for them.
    4. CHECK: It is one of the integrity constraints in DBMS. It keeps the check that integrity of data is maintained before and after the completion of the CRUD.
    5. PRIMARY KEY: This is an attribute or set of attributes that can uniquely identify each entity in the entity set. The primary key must contain unique as well as not null values.
    6. FOREIGN KEY: Whenever there is some relationship between two entities, there must be some common attribute between them. This common attribute must be the primary key of an entity set and will become the foreign key of another entity set. This key will prevent every action which can result in loss of connection between tables.

CodeHelp

  1. Table of the relationship set is made.
  2. Attributes includes primary keys of entity set and aggregation set’s entities.
  3. Also, add descriptive attribute if any on the relationship.

CodeHelp

LEC-9: SQL in 1-Video

  1. SQL : Structured Query Language, used to access and manipulate data.
  2. SQL used CRUD operations to communicate with DB.
    1. CREATE - execute INSERT statements to insert new tuple into the relation.
    2. READ - Read data already in the relations.
    3. UPDATE - Modify already inserted data in the relation.
    4. DELETE - Delete specific data point/tuple/row or multiple rows. 3. SQL is not DB, is a query language.
  3. What is RDBMS? (Relational Database Management System)
    1. Software that enable us to implement designed relational model.
    2. e.g., MySQL, MS SQL, Oracle, IBM etc.
    3. Table/Relation is the simplest form of data storage object in R-DB.
    4. MySQL is open-source RDBMS, and it uses SQL for all CRUD operations
  4. MySQL used client-server model, where client is CLI or frontend that used services provided by MySQL server. 6. Difference between SQL and MySQL
    1. SQL is Structured Query language used to perform CRUD operations in R-DB, while MySQL is a RDBMS used to store, manage and administrate DB (provided by itself) using SQL.

SQL DATA TYPES (Ref: https://www.w3schools.com/sql/sql_datatypes.asp)

  1. In SQL DB, data is stored in the form of tables.
  2. Data can be of different types, like INT, CHAR etc.

DATATYPE Description

CHAR string(0-255), string with size = (0, 255], e.g., CHAR(251) VARCHAR string(0-255)

TINYTEXT String(0-255)

TEXT string(0-65535)

BLOB string(0-65535)

MEDIUMTEXT string(0-16777215)

MEDIUMBLOB string(0-16777215)

LONGTEXT string(0-4294967295)

LONGBLOB string(0-4294967295)

TINYINT integer(-128 to 127)

SMALLINT integer(-32768 to 32767)

MEDIUMINT integer(-8388608 to 8388607)

INT integer(-2147483648 to 2147483647)

BIGINT integer (-9223372036854775808 to

FLOAT Decimal with precision to 23 digits

DOUBLE Decimal with 24 to 53 digits

DATATYPE

CodeHelp

DATA RETRIEVAL LANGUAGE (DRL)

  1. Syntax: SELECT FROM ;
  2. Order of execution from RIGHT to LEFT.
  3. Q. Can we use SELECT keyword without using FROM clause?
    1. Yes, using DUAL Tables.
    2. Dual tables are dummy tables created by MySQL, help users to do certain obvious actions without referring to user defined tables.
    3. e.g., SELECT 55 + 11; SELECT now(); SELECT ucase(); etc. 4. WHERE
    4. Reduce rows based on given conditions.
    5. E.g., SELECT * FROM customer WHERE age > 18; 5. BETWEEN
    6. SELECT * FROM customer WHERE age between 0 AND 100;
    7. In the above e.g., 0 and 100 are inclusive. 6. IN
    8. Reduces OR conditions;
    9. e.g., SELECT * FROM officers WHERE officer_name IN ('Lakshay', ‘Maharana Pratap', ‘Deepika’); 7. AND/OR/NOT
    10. AND: WHERE cond1 AND cond
    11. OR: WHERE cond1 OR cond
    12. NOT: WHERE col_name NOT IN (1,2,3,4); 8. IS NULL
    13. e.g., SELECT * FROM customer WHERE prime_status is NULL; 9. Pattern Searching / Wildcard (‘%’, ‘_’)
    14. ‘%’, any number of character from 0 to n. Similar to ‘*’ asterisk in regex.
    15. ‘_’, only one character.
    16. SELECT * FROM customer WHERE name LIKE ‘%p_’; 10. ORDER BY
    17. Sorting the data retrieved using WHERE clause.
    18. ORDER BY DESC;
    19. DESC = Descending and ASC = Ascending
    20. e.g., SELECT * FROM customer ORDER BY name DESC; 11. GROUP BY
    21. GROUP BY Clause is used to collect data from multiple records and group the result by one or more column. It is generally used in a SELECT statement.
    22. Groups into category based on column given.
    23. SELECT c1, c2, c3 FROM sample_table WHERE cond GROUP BY c1, c2, c3.
    24. All the column names mentioned after SELECT statement shall be repeated in GROUP BY, in order to successfully execute the query.
    25. Used with aggregation functions to perform various actions.
      1. COUNT()
      2. SUM()
      3. AVG()
      4. MIN()
      5. MAX() 12. DISTINCT
    26. Find distinct values in the table.
    27. SELECT DISTINCT(col_name) FROM table_name;
    28. GROUP BY can also be used for the same
      1. “Select col_name from table GROUP BY col_name;” same output as above DISTINCT query.

CodeHelp

  1. SQL is smart enough to realise that if you are using GROUP BY and not using any aggregation function, then you mean “DISTINCT”. 13. GROUP BY HAVING
  2. Out of the categories made by GROUP BY, we would like to know only particular thing (cond).
  3. Similar to WHERE.
  4. Select COUNT(cust_id), country from customer GROUP BY country HAVING COUNT(cust_id) > 50;
  5. WHERE vs HAVING
  6. Both have same function of filtering the row base on certain conditions.
  7. WHERE clause is used to filter the rows from the table based on specified condition
  8. HAVING clause is used to filter the rows from the groups based on the specified condition.
  9. HAVING is used after GROUP BY while WHERE is used before GROUP BY clause.
  10. If you are using HAVING, GROUP BY is necessary.
  11. WHERE can be used with SELECT, UPDATE & DELETE keywords while GROUP BY used with SELECT.

CONSTRAINTS (DDL)

  1. Primary Key
    1. PK is not null, unique and only one per table. 2. Foreign Key
  2. FK refers to PK of other table.
  3. Each relation can having any number of FK.
  4. CREATE TABLE ORDER ( id INT PRIMARY KEY, delivery_date DATE, order_placed_date DATE, cust_id INT, FOREIGN KEY (cust_id) REFERENCES customer(id) ); 3. UNIQUE
  5. Unique, can be null, table can have multiple unique attributes.
  6. CREATE TABLE customer ( … email VARCHAR(1024) UNIQUE, … ); 4. CHECK
  7. CREATE TABLE customer ( … CONSTRAINT age_check CHECK (age > 12), … );
  8. “age_check”, can also avoid this, MySQL generates name of constraint automatically.

CodeHelp

FOREIGN KEY(cust_id) REFERENCES customer(id) ON DELETE CASCADE );

  1. ON DELETE NULL - ( can FK have null values? )
    1. CREATE TABLE ORDER ( order_id int PRIMARY KEY, delivery_date DATE, cust_id INT, FOREIGN KEY(cust_id) REFERENCES customer(id) ON DELETE SET NULL ); 4. REPLACE
  2. Primarily used for already present tuple in a table.
  3. As UPDATE, using REPLACE with the help of WHERE clause in PK, then that row will be replaced.
  4. As INSERT, if there is no duplicate data new tuple will be inserted.
  5. REPLACE INTO student (id, class) VALUES(4, 3);
  6. REPLACE INTO table SET col1 = val1, col2 = val2;

JOINING TABLES

  1. All RDBMS are relational in nature, we refer to other tables to get meaningful outcomes.
  2. FK are used to do reference to other table.
  3. INNER JOIN
    1. Returns a resultant table that has matching values from both the tables or all the tables.
    2. SELECT column-list FROM table1 INNER JOIN table2 ON condition INNER JOIN table3 ON condition …; 3. Alias in MySQL (AS)
      1. Aliases in MySQL is used to give a temporary name to a table or a column in a table for the purpose of a particular query. It works as a nickname for expressing the tables or column names. It makes the query short and neat.
      2. SELECT col_name AS alias_name FROM table_name;
      3. SELECT col_name1, col_name2,... FROM table_name AS alias_name;
  4. OUTER JOIN 1. LEFT JOIN 1. This returns a resulting table that all the data from left table and the matched data from the right table. 2. SELECT columns FROM table LEFT JOIN table2 ON Join_Condition; 2. RIGHT JOIN 1. This returns a resulting table that all the data from right table and the matched data from the left table. 2. SELECT columns FROM table RIGHT JOIN table2 ON join_cond; 3. FULL JOIN 1. This returns a resulting table that contains all data when there is a match on left or right table data. 2. Emulated in MySQL using LEFT and RIGHT JOIN. 3. LEFT JOIN UNION RIGHT JOIN. 4. SELECT columns FROM table1 as t1 LEFT JOIN table2 as t2 ON t1.id = t2.id UNION SELECT columns FROM table1 as t1 RIGHT JOIN table2 as t2 ON t1.id = t2.id; 5. UNION ALL, can also be used this will duplicate values as well while UNION gives unique values. 5. CROSS JOIN
    1. This returns all the cartesian products of the data present in both tables. Hence, all possible variations are reflected in the output.
    2. Used rarely in practical purpose.
    3. Table-1 has 10 rows and table-2 has 5, then resultant would have 50 rows.
    4. SELECT column-lists FROM table1 CROSS JOIN table2; 6. SELF JOIN

CodeHelp

  1. It is used to get the output from a particular table when the same table is joined to itself.
  2. Used very less.
  3. Emulated using INNER JOIN.
  4. SELECT columns FROM table as t1 INNER JOIN table as t2 ON t1.id = t2.id; 7. Join without using join keywords.
  5. SELECT * FROM table1, table2 WHERE condition;
  6. e.g., SELECT artist_name, album_name, year_recordedFROM artist, albumWHERE artist.id = album.artist_id;

SET OPERATIONS

  1. Used to combine multiple select statements.
  2. Always gives distinct rows.

3. UNION

  1. Combines two or more SELECT statements.
  2. SELECT * FROM table UNION SELECT * FROM table2;
  3. Number of column, order of column must be same for table1 and table2. 4. INTERSECT
  4. Returns common values of the tables.
  5. Emulated.
  6. SELECT DISTINCT column-list FROM table-1 INNER JOIN table-2 USING(join_cond);
  7. SELECT DISTINCT * FROM table1 INNER JOIN table2 ON USING(id); 5. MINUS
  8. This operator returns the distinct row from the first table that does not occur in the second table.
  9. Emulated.
  10. SELECT column_list FROM table1 LEFT JOIN table2 ON condition WHERE table2.column_name IS NULL;
  11. e.g., SELECT id FROM table-1 LEFT JOIN table-2 USING(id) WHERE table-2.id IS NULL;

SUB QUERIES

  1. Outer query depends on inner query.
  2. Alternative to joins.
  3. Nested queries.
  4. SELECT column_list (s) FROM table_name WHERE column_name OPERATOR (SELECT column_list (s) FROM table_name [WHERE]);
  5. e.g., SELECT * FROM table1 WHERE col1 IN (SELECT col1 FROM table1);
  6. Sub queries exist mainly in 3 clauses
    1. Inside a WHERE clause.

JOIN SET Operations

Combines multiple tables based on matching condition.

Combination is resulting set from two or more SELECT statements. Column wise combination. Row wise combination.

Data types of two tables can be different. Datatypes of corresponding columns from each table should be the same. Can generate both distinct or duplicate rows. Generate distinct rows.

The number of column(s) selected may or may not be the same from each table.

The number of column(s) selected must be the same from each table. Combines results horizontally. Combines results vertically.

CodeHelp