SQL Queries
(1) The SQL
CREATE TABLE Statement:
Syntax
CREATE TABLE
table_name (column1 datatype,column2 datatype,column3 datatype,....);
Example
CREATE TABLE
Persons (PersonID int, LastName varchar(255),FirstName varchar(255),Address
varchar(255), City varchar(255));
(2) SQL
INSERT INTO Statement
INSERT INTO
table_name (column1, column2, column3, ...) VALUES (value1,value2, value3,
...);
Example
INSERT INTO
Customers (CustomerName, ContactName, Address, City, PostalCode,Country)VALUES
('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');
(3) SQL
SELECT Statement
(a) SELECT
column1, column2, ... FROM table_name; (b)
SELECT * FROM table_name;
Example
(a) SELECT
CustomerName, City FROM Customers; (b)
SELECT * FROM Customers;
(4) SQL
SELECT DISTINCT Statement
SELECT
DISTINCT column1, column2, ... FROM table_name;
Example
SELECT
Country FROM Customers;
(5) The SQL
WHERE Clause
SELECT
column1, column2, ... FROM table_name WHERE condition;
Example
SELECT *
FROM Customers WHERE Country='Mexico';
(6) The SQL
ORDER BY Keyword
SELECT
column1, column2, ... FROM table_name ORDER BY column1, column2, ...ASC|DESC;
Example
SELECT *
FROM Customers ORDER BY Country;
(7) SQL
UPDATE Statement
UPDATE
table_name SET column1 = value1, column2 = value2, ... WHERE condition;
Example
UPDATE
Customers SET ContactName = 'Alfred Schmidt', City= 'Frankfurt' WHERE CustomerID
= 1;
(8) SQL
DELETE Statement
DELETE FROM
table_name WHERE condition;
Example
DELETE FROM
Customers WHERE CustomerName='Alfreds Futterkiste';
(9) SQL
MIN() and MAX() Functions
MIN() Syntax
SELECT
MIN(column_name) FROM table_name WHERE condition;
MAX() Syntax
SELECT
MAX(column_name) FROM table_name WHERE condition;
Example
SELECT
MIN(Price) AS SmallestPrice FROM Products;
SELECT
MAX(Price) AS LargestPrice FROM Products;
(10) SQL
COUNT(), AVG() and SUM() Functions
COUNT()
Syntax
SELECT
COUNT(column_name) FROM table_name WHERE condition;
AVG() Syntax
SELECT
AVG(column_name) FROM table_name WHERE condition;
SUM() Syntax
SELECT
SUM(column_name) FROM table_name WHERE condition;
Example
SELECT
COUNT(ProductID) FROM Products;
SELECT
AVG(Price) FROM Products;
SELECT
SUM(Quantity) FROM OrderDetails;
(11) SQL
LIKE Operator
SELECT
column1, column2, ... FROM table_name WHERE columnN LIKE pattern;
Example
SELECT *
FROM Customers WHERE CustomerName LIKE 'a%';
(12) SQL
UNION Operator
SELECT
column_name(s) FROM table1
UNION
SELECT
column_name(s) FROM table2;
Example
SELECT City
FROM Customers UNION SELECT City FROM Suppliers ORDER BY City;
(13) SQL
GROUP BY Statement
SELECT
column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) ORDER BY
column_name(s);
Example
SELECT
COUNT(CustomerID), Country FROM Customers GROUP BY Country;
(14) SQL
HAVING Clause
SELECT
column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) HAVING
condition ORDER BY column_name(s);
Example
SELECT
COUNT(CustomerID), Country FROM Customers GROUP BY Country HAVING
COUNT(CustomerID) > 5;
(15) SQL
DROP TABLE Statement
DROP TABLE
table_name;
Example
DROP TABLE
Shippers;
(16) SQL
ALTER TABLE Statement
(a) ALTER
TABLE table_name ADD column_name datatype;
(b) ALTER
TABLE table_name MODIFY COLUMN column_name datatype;
Example
ALTER TABLE
Persons ADD DateOfBirth date;
(17) SQL NOT
NULL Constraint
Example
CREATE TABLE
Persons ( ID int NOT NULL, LastName varchar(255) NOT NULL,
FirstName
varchar(255) NOT NULL, Age int );
(18) SQL
UNIQUE Constraint
Example
CREATE TABLE
Persons (ID int NOT NULL, LastName varchar(255) NOT NULL,
FirstName
varchar(255), Age int, UNIQUE (ID));
(19) SQL
PRIMARY KEY Constraint
Example
CREATE TABLE
Persons (ID int NOT NULL, LastName varchar(255) NOT NULL,
FirstName
varchar(255), Age int, PRIMARY KEY (ID));
(20) SQL
FOREIGN KEY Constraint
Example
CREATE TABLE
Orders (OrderID int NOT NULL, OrderNumber int NOT NULL,
PersonID
int, PRIMARY KEY (OrderID), FOREIGN KEY (PersonID) REFERENCES
Persons(PersonID));
(21) SQL
Working With Dates
Example
SELECT *
FROM Orders WHERE OrderDate='2008-11-11'
Search Topics :
learn mysql online, learn mysql queries, learn mysql pdf, learn mysql workbench, learn mysql online free, learn mysql from scratch, learn mysql for beginners, learn mysql advanced, learn mysql database, learn mysql and php, learn mysql administration, learn mysql app, learn about mysql, learn mysql database administration, learn php mysql and javascript, learn php and mysql development from scratch, learn mysql basics, learn mysql book, learn mysql beginners, learn mysql from basics to advanced, learn mysql step by step, learn mysql for beginners pdf, learn php and mysql book, what to learn before mysql, learn mysql command line, learn mysql codecademy, learn mysql commands, learn mysql source code, learn mysql database pdf, learn mysql dump, how to learn mysql database for beginners, learn mysql in one day, how to learn mysql database step by step pdf, learn mysql expert, learn mysql with examples, learn mysql from basic, learn mysql functions, learn php mysql free, learn php mysql fast, learn mysql game, learn mysql in hindi, learn mysql in 24 hours pdf, how learn mysql, learn mysql in linux, learn mysql in kolkata, learn mysql in arabic, learn mysql online interactive, learn joins in mysql, should i learn mysql or postgresql, can i learn mysql without sql, should i learn mysql, should i learn mysql or sql server, should i learn mysql or mongodb, should i learn mysql or sql, should i learn mysql or oracle, can i learn mysql in one day, learn mysql javatpoint, learn mysql joins, learn node.js mysql, learn mysql or postgresql, learn mysql or sql server, learn oracle mysql, learn php mysql online free, learn sql or mysql, learn mysql python, learn mysql php, learn mysql programming, learn pdo mysql php, learn mysql quora, learn advanced mysql queries, best website to learn mysql quora, learn mysql reddit, how long to learn mysql reddit, how to learn mysql root password, learn mysql stored procedure, learn mysql server, learn mysql shell, learn mysql sql, learn mysql scripting, learn mysql and solve 42 practical problems, learn mysql tutorial, learn mysql tutorials point, learn mysql udemy, learn to use mysql, learn sql using mysql database, learn mysql version, learn mysql w3schools, learn mysql with python, learn mysql workbench pdf, learn mysql with php, learn php and mysql with 33 projects, learn x in y mysql, learn mysql youtube, learn php and mysql youtube,
Comments
Post a Comment