SQL Apnacollege Youtube

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 31

2 columns can be a primary key in which the individual columns can have repeating values but their

combination together will be unique


Example:

Here id , name can repeat individually but when combination of both occurs it will be unique.
This could be any name
Here the query will return an error because the no.of columns used in the select statement(except
aggregate columns) has to be in the group by (here the column name is missing in the group by).

Therefore the corrected query:


Having clause is similar to where clause but the difference is that having clause is used to apply
conditions on grouped column or group by .
Where clause puts condition on rows whereas having puts condition on groups.

Here where condition puts filter on grade whereas having condition puts condition ongroup by
column.
The complete picture

Set_sql_safe_updates=0;

This query is used to turn the safe mode off which is by default turned on in my sql from preventing
updating the table at first.
Eer diagram created by using the database->reverse engineer option
Alter means to change the schema or design(columns,datatypes,constraints), basically to add, drop
column and rename table.

ALTER TABLE table_name RENAME COLUMN old_column_name TO new_column_name;


This command is used to change the name of a column to a new column name.

1. To add a column.
Drop table command is used to delete the entire table completely whereas truncate command deletes

The data inside the table. You can still add the data inside the table.
In mysql there is no full outer join or outer join therefore we use UNION
Output:

RIGHT EXCLUSIVE JOIN:


OUTPUT:
** The output only gives the unique or distinct values from both the tables.

If we want to combine all the data then use UNION ALL.

Ex:
Step1

Step 2
For example: sales team want sales related data from a table/database which has large no of columns
and also data that is irrelevant/not required for them and also we want to restrict them from viewing all
the data for ex:( credit card numbers which is useful for accounts team). In this case we create views
which is a temporary /virtual table created from the original table.

View can also be deleted:

Deleting view doesn’t affect the tables in database.

You might also like