0% found this document useful (0 votes)
1 views3 pages

SQL Intro

The document provides a comprehensive overview of basic MySQL commands for database management, including creating, dropping, and using databases and tables. It details SQL operations such as inserting, updating, deleting records, and using aggregate functions like MIN, MAX, COUNT, SUM, and AVG. Additionally, it includes examples of filtering data and performing joins between tables.

Uploaded by

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

SQL Intro

The document provides a comprehensive overview of basic MySQL commands for database management, including creating, dropping, and using databases and tables. It details SQL operations such as inserting, updating, deleting records, and using aggregate functions like MIN, MAX, COUNT, SUM, and AVG. Additionally, it includes examples of filtering data and performing joins between tables.

Uploaded by

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

show all db:

SHOW DATABASES;
open db:
USE w3schools;

show all table:


SHOW TABLES;
open table:
SELECT * FROM products;

CREATE DATABASE:
CREATE DATABASE csc_class;
DROP DATABASE:
DROP DATABASE csc_class;

CREATE TABLE:
CREATE TABLE Customers (
CustomerID INT PRIMARY KEY AUTO_INCREMENT,
CustomerName VARCHAR(100) NOT NULL,
ContactName VARCHAR(100),
Address VARCHAR(255),
City VARCHAR(100),
PostalCode VARCHAR(20),
Country VARCHAR(100)
);

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode,


Country)
VALUES
('Taj Stores', 'Arun Kumar', '123 MG Road', 'Chennai', '600001', 'India'),
('Sunrise Mart', 'Priya Ramesh', '45 Anna Salai', 'Chennai', '600002', 'India'),
('Global Traders', 'John Smith', '12 High Street', 'London', 'SW1A 1AA', 'UK'),
('Green Grocery', 'Emily Clark', '98 Bay Area', 'San Francisco', '94101', 'USA');

DROP TABLE:
DROP TABLE table_name;

INSERT INTO:
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode,
Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');

MySQL UPDATE:
UPDATE Customers
SET ContactName = 'Alfred Schmidt', City = 'Frankfurt'
WHERE CustomerID = 1;

MySQL DELETE Statement:


DELETE FROM customers WHERE CustomerID=94;

Filter:
SELECT * FROM Customers WHERE Country = 'Mexico';

SELECT * FROM Customers WHERE CustomerName LIKE 'La%';


SELECT * FROM Customers WHERE CustomerName LIKE 'A';

MIN() and MAX() Functions:


SELECT MIN(Price) AS SmallestPrice FROM Products;
SELECT MAX(Price) AS BigPrice FROM Products;

SELECT MIN(Price) AS SmallestPrice


FROM Products
WHERE Price BETWEEN 50 AND 100;

SELECT Price AS SmallestPrice


FROM Products
WHERE Price BETWEEN 50 AND 100;

INNER JOIN:

SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate


FROM Orders
INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;

LEFT JOIN:
RIGHT JOIN:

SQL Aggregate Functions:


MIN() - returns the smallest value within the selected column
MAX() - returns the largest value within the selected column
COUNT() - returns the number of rows in a set
SELECT COUNT(*) FROM Products;

SUM() - returns the total sum of a numerical column


SELECT SUM(Quantity) FROM Order_Details;

AVG() - returns the average value of a numerical column


SELECT AVG(Price) FROM Products;

Shell
mysql -u root -p

https://phoenixnap.com/kb/how-to-list-all-databases-mysql#:~:text=To%20show%20all
%20databases%20in%20MySQL%2C%20follow%20the,3%203.%20Alternatively%2C%20show%20the
%20database%20schemas%20with%3A

mysql -u root -p

-u---user name
-p---password

To show all available databases enter the following SQL command:


SHOW DATABASES;

to open db:
use db_name;

SHOW TABLES;
To Show table:

SELECT * FROM table_name;

You might also like