SQL pd
SQL pd
Database:
Create database <name>;
Use <name>;
To drop database:
Tables:
Create table table_name
(column_name datatype,
Column_name datatype);
Values(data,data,…,.,.,.,,.,.);
PRIMARY KEY:
S.no is common in both the employee name data and the salary the achieved table.
CRUD:
Create:
READ:
A LIAS:(as)
UPDATE:
Syntax:
update <table name> set <column name> = <to be update> where condition.
Here, update, set, and where are used to change the data permanently.
DELETE:
Where <condition>;
STRING OPERATIONS:
1. CONCATE:
FROM employees;
3. SUBSTRING:
Select concat_ws(substr(title, 1, 4), ‘ ‘, ‘is published by’, published_by) as datas from books;
4. REPLACE:
case sensitive
select replace(‘Hello world’ ‘Hell’ ‘*766’) as new name; opt *766o world.
select concat(substr(replace(title,'e','3'), 1, 10), ' ', 'was written by',' ', author_fname,' ',
author_1name)as datas from books;
5.REVERSE:
PALINDROME:
6. CHARACTER LENGTH:
7.UPPER/ LOWER:
select upper(name) from books;
SELECTION REFINING:
DISTINCT KEYWORD:
Syntax:
ORDER BY:
Syntax:
Select <column names> from <table name> order by <column name to be orderd>; you can
also declare by indexes like in th space of <> you can give indexes like1,2.
LIMIT:
Syntax:
Select title, author_fname, released_year from books order by released_year desc limit 5;
LIKE:
It is helpful in searching in data with only a thing that is in the sentence, meaning if you
remember only part of sentence then also you can search the element.
It uses % and _ to search in the string.
Syntax:
AGREEGATE FUNCTIONS:
COUNT:
Syntax:
MIN/MAX:
Gives min and max of integer values using min and max
SELECT department,
MIN(salary) AS min_salary,
MAX(salary) AS max_salary
FROM employees
GROUP BY department;
select current_time();
select date(current_timestamp());
select time(current_timestamp());
select time();
select year(current_timestamp());
select month(current_timestamp());
select day(current_timestamp());
select hour(current_timestamp());
SELECT MINUTE(CURRENT_TIMESTAMP());
SELECT SECOND(CURRENT_TIMESTAMP());
SYNTAX:
DATEDIFF:
SYNTAX:
TIMEDIFF:
SYNTAX:
DATE_ADD:
SYNTAX:
LOGICAL OPERATORS:
NOT EQUAL:
select title, released_year from books where title NOT like 'W%';
GREATER THAN:
LESS THAN:
AND:
select title, released_year, author_1name from books where author_1name = 'lahiri' and
released_year < '2017';
OR:
select title, author_1name from books where author_1name = 'eggers' or 'chabon';
IN/NOT IN:
BETWEEN:
select title, pages from books where pages between 100 and 200;
CASE ELSE:
case
when title = 'just kids' or title = ' A Heartbreaking Work of Staggering Genius' then 'Memories'
else 'Novel'
end as type
from books;
RELATIONSHIP:
ONE TO ONE
ONE TO MANY
MANY TO MANY
FOREIGN KEY:
FOR EXAMPLE:
Last_name varchar(100),
);
Customer_id int,
);
INNER JOIN:
Join orders
On coutomers.id = orders.customer_id;
LEFT JOIN:
on customers.id = orders.customer_id;
RIGHT JOIN:
on customers.id = orders.customer_id;