0% found this document useful (0 votes)
56 views

My SQL Part3

A subquery is a query nested inside another query statement. The subquery executes first and its results are used by the outer query. Views are virtual tables that display data stored in other tables. Indexes improve the speed of operations in a table by indexing one or more columns, but should be avoided on small tables or tables with frequent updates to avoid performance issues.

Uploaded by

mamash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

My SQL Part3

A subquery is a query nested inside another query statement. The subquery executes first and its results are used by the outer query. Views are virtual tables that display data stored in other tables. Indexes improve the speed of operations in a table by indexing one or more columns, but should be avoided on small tables or tables with frequent updates to avoid performance issues.

Uploaded by

mamash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Subqueries

 A subquery is a query that appears inside another query


 Subquery with Select Statement statement. Subqueries are also referred to as sub- SELECT s
or nested SELECT s. The full SELECT syntax is valid in
subqueries.
A subquery is a SELECT statement within another statement.
SELECT column_list (s) FROM  table

 A MySQL subquery is called an inner query while the query


_name   that contains the subquery is called an outer query.
 A subquery can be used anywhere that expression is used and
WHERE  column_name OPERATOR   must be closed in parentheses.

   (SELECT column_list (s)  FROM ta  The subquery (inner query) executes once before the main
query.
ble_name [WHERE])    The result of the subquery is used by the main query (outer
query).
SQL View
VIEWS are virtual tables that do not store any data of
Create View Syntax


their own but display data stored in other tables. In other
CREATE VIEW view_name AS SELECT column1, words, VIEWS are nothing but SQL Queries. A view can
column2...FROM table_name WHERE [condition]; contain all or a few rows from a table. A MySQL view
can show data from one table or many tables.
 The parameters are:
 CREATE VIEW: The command “CREATE VIEW ‘view
name'” instructs MySQL to create a view object named
‘view name’ in the database.
 AS SELECT: The SQL statements to be packed in the
MySQL Views are referred to as “AS SELECT
statements.” A SELECT statement can include data from
one or more tables.
Updating a View
 A view can be updated under certain conditions:
 The SELECT clause may not contain the keyword DISTINCT.
 The SELECT clause may not contain summary functions.
 The SELECT clause may not contain set functions.
 The SELECT clause may not contain set operators.
 The SELECT clause may not contain an ORDER BY clause.
 The FROM clause may not contain multiple tables.
 The WHERE clause may not contain subqueries.
 The query may not contain GROUP BY or HAVING.
 Calculated columns may not be updated.
 All NOT NULL columns from the base table must be included in the view in order for the INSERT query to function.
Dropping Views
 Syntax  The SQL DROP View statement is
DROP VIEW view_name; used to delete an existing view,
along with its definition and other
information.
 Once the view is dropped, all the
permissions for it will also be
removed. We can also use this
statement to drop indexed views.
Index
 Create Index Syntax  A database index is a data structure
CREATE UNIQUE INDEX that improves the speed of
index_name ON table_name operations in a table.
( column1, column2,...);  Indexes can be created using one or
 Displaying INDEX Information more columns.

SHOW INDEX FROM table_name;


When should indexes be avoided?
 Indexes should not be used on small tables.
 Tables that have frequent, large batch update or insert operations.
 Indexes should not be used on columns that contain a high number of NULL values.
 Columns that are frequently manipulated should not be indexed

You might also like