Last login: Fri Aug 18 19:17:12 on ttys008
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
Lokranjans-MacBook-Air:~ lokranjan$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.33 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database Project;
Query OK, 1 row affected (0.01 sec)
mysql> use Project;
Database changed
mysql> CREATE TABLE Customers (
-> customer_id INT AUTO_INCREMENT PRIMARY KEY,
-> first_name VARCHAR(50),
-> last_name VARCHAR(50),
-> email VARCHAR(100),
-> address VARCHAR(255),
-> city VARCHAR(100),
-> state VARCHAR(50),
-> zip_code VARCHAR(10)
-> );
Query OK, 0 rows affected (0.02 sec)
mysql> CREATE TABLE Products (
-> product_id INT AUTO_INCREMENT PRIMARY KEY,
-> name VARCHAR(100),
-> price DECIMAL(10, 2),
-> description TEXT
-> );
Query OK, 0 rows affected (0.01 sec)
mysql> CREATE TABLE Orders (
-> order_id INT AUTO_INCREMENT PRIMARY KEY,
-> customer_id INT,
-> order_date DATE,
-> total_amount DECIMAL(10, 2),
-> FOREIGN KEY (customer_id) REFERENCES Customers(customer_id)
-> );
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE TABLE Order_Items (
-> order_item_id INT AUTO_INCREMENT PRIMARY KEY,
-> order_id INT,
-> product_id INT,
-> quantity INT,
-> subtotal DECIMAL(10, 2),
-> FOREIGN KEY (order_id) REFERENCES Orders(order_id),
-> FOREIGN KEY (product_id) REFERENCES Products(product_id)
-> );
Query OK, 0 rows affected (0.02 sec)
mysql> show tables;
+-------------------+
| Tables_in_project |
+-------------------+
| Customers |
| Order_Items |
| Orders |
| Products |
+-------------------+
4 rows in set (0.01 sec)
mysql> Insert dummy data into Customers table
-> INSERT INTO Customers (first_name, last_name, email, address, city, state,
zip_code)
-> VALUES
-> ('John', 'Doe', 'john.doe@example.com', '123 Main St', 'Anytown', 'CA',
'12345'),
-> ('Jane', 'Smith', 'jane.smith@example.com', '456 Oak Ave', 'Sometown',
'NY', '67890'),
-> ('Michael', 'Johnson', 'michael.johnson@example.com', '789 Elm Rd',
'Cityville', 'TX', '54321'),
-> ('Emily', 'Lee', 'emily.lee@example.com', '101 Pine Dr', 'Townsville',
'IL', '98765'),
-> ('William', 'Wong', 'william.wong@example.com', '555 Cedar Ln',
'Villagetown', 'FL', '13579');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'data
into Customers table
INSERT INTO Customers (first_name, last_name, email, a' at line 1
mysql> INSERT INTO Customers (first_name, last_name, email, address, city, state,
zip_code)
-> VALUES
-> ('John', 'Doe', 'john.doe@example.com', '123 Main St', 'Anytown', 'CA',
'12345'),
-> ('Jane', 'Smith', 'jane.smith@example.com', '456 Oak Ave', 'Sometown',
'NY', '67890'),
-> ('Michael', 'Johnson', 'michael.johnson@example.com', '789 Elm Rd',
'Cityville', 'TX', '54321'),
-> ('Emily', 'Lee', 'emily.lee@example.com', '101 Pine Dr', 'Townsville',
'IL', '98765'),
-> ('William', 'Wong', 'william.wong@example.com', '555 Cedar Ln',
'Villagetown', 'FL', '13579');
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> INSERT INTO Products (name, price, description)
-> VALUES
-> ('Laptop', 799.99, 'High-performance laptop with a sleek design.'),
-> ('Smartphone', 499.00, 'Latest smartphone with advanced features.'),
-> ('Headphones', 129.95, 'Noise-canceling headphones for immersive
audio.'),
-> ('Tablet', 349.50, 'Portable tablet with a high-resolution display.'),
-> ('Camera', 699.00, 'Professional DSLR camera for stunning photos.'),
-> ('Smartwatch', 199.99, 'Smartwatch with fitness tracking and
notifications.');
Query OK, 6 rows affected (0.00 sec)
Records: 6 Duplicates: 0 Warnings: 0
mysql> INSERT INTO Orders (customer_id, order_date, total_amount)
-> VALUES
-> (1, '2023-07-24', 1699.97),
-> (2, '2023-07-23', 798.00),
-> (3, '2023-07-22', 977.45),
-> (4, '2023-07-21', 2248.95),
-> (5, '2023-07-20', 499.99);
Query OK, 5 rows affected (0.01 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> INSERT INTO Order_Items (order_id, product_id, quantity, subtotal)
-> VALUES
-> (1, 1, 2, 1599.98),
-> (1, 3, 1, 129.95),
-> (2, 2, 1, 499.00),
-> (3, 4, 3, 2098.50),
-> (4, 5, 1, 699.00),
-> (5, 6, 1, 199.99);
Query OK, 6 rows affected (0.00 sec)
Records: 6 Duplicates: 0 Warnings: 0
mysql> desc Customers;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| customer_id | int | NO | PRI | NULL | auto_increment |
| first_name | varchar(50) | YES | | NULL | |
| last_name | varchar(50) | YES | | NULL | |
| email | varchar(100) | YES | | NULL | |
| address | varchar(255) | YES | | NULL | |
| city | varchar(100) | YES | | NULL | |
| state | varchar(50) | YES | | NULL | |
| zip_code | varchar(10) | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
8 rows in set (0.01 sec)
mysql> INSERT INTO Customers (first_name, last_name, email, address, city, state,
zip_code)
-> VALUES
-> ('Rahul', 'Kumar', 'rahul@example.com', '123 Main St', 'Mumbai', 'MH',
'400001'),
-> ('Priya', 'Sharma', 'priya@example.com', '456 Park Ave', 'Delhi', 'DL',
'110001'),
-> ('Rajesh', 'Patel', 'rajesh@example.com', '789 Oak Rd', 'Ahmedabad',
'GJ', '380001'),
-> ('Sanya', 'Gupta', 'sanya@example.com', '101 Pine Dr', 'Bangalore',
'KA', '560001'),
-> ('Manish', 'Singh', 'manish@example.com', '555 Cedar Ln', 'Kolkata',
'WB', '700001'),
-> ('Neha', 'Desai', 'neha@example.com', '888 Maple Blvd', 'Chennai', 'TN',
'600001'),
-> ('Ravi', 'Verma', 'ravi@example.com', '333 Elm St', 'Hyderabad', 'TS',
'500001'),
-> ('Anjali', 'Reddy', 'anjali@example.com', '222 Birch Ave', 'Pune', 'MH',
'411001'),
-> ('Rohit', 'Choudhury', 'rohit@example.com', '777 Oak Rd', 'Jaipur',
'RJ', '302001');
Query OK, 9 rows affected (0.00 sec)
Records: 9 Duplicates: 0 Warnings: 0
mysql> select * from Customers;
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
| customer_id | first_name | last_name | email | address
| city | state | zip_code |
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
| 1 | John | Doe | john.doe@example.com | 123 Main St
| Anytown | CA | 12345 |
| 2 | Jane | Smith | jane.smith@example.com | 456 Oak Ave
| Sometown | NY | 67890 |
| 3 | Michael | Johnson | michael.johnson@example.com | 789 Elm Rd
| Cityville | TX | 54321 |
| 4 | Emily | Lee | emily.lee@example.com | 101 Pine Dr
| Townsville | IL | 98765 |
| 5 | William | Wong | william.wong@example.com | 555 Cedar Ln
| Villagetown | FL | 13579 |
| 6 | Rahul | Kumar | rahul@example.com | 123 Main St
| Mumbai | MH | 400001 |
| 7 | Priya | Sharma | priya@example.com | 456 Park Ave
| Delhi | DL | 110001 |
| 8 | Rajesh | Patel | rajesh@example.com | 789 Oak Rd
| Ahmedabad | GJ | 380001 |
| 9 | Sanya | Gupta | sanya@example.com | 101 Pine Dr
| Bangalore | KA | 560001 |
| 10 | Manish | Singh | manish@example.com | 555 Cedar Ln
| Kolkata | WB | 700001 |
| 11 | Neha | Desai | neha@example.com | 888 Maple
Blvd | Chennai | TN | 600001 |
| 12 | Ravi | Verma | ravi@example.com | 333 Elm St
| Hyderabad | TS | 500001 |
| 13 | Anjali | Reddy | anjali@example.com | 222 Birch
Ave | Pune | MH | 411001 |
| 14 | Rohit | Choudhury | rohit@example.com | 777 Oak Rd
| Jaipur | RJ | 302001 |
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
14 rows in set (0.00 sec)
mysql> Insert into Customers
-> values('Arjun','Aalu','pushpa@example.com','669 Side
Rd','Mysuru','KA','570008');
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> Drop Customers;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'Customers' at line 1
mysql> drop table Customers;
ERROR 3730 (HY000): Cannot drop table 'customers' referenced by a foreign key
constraint 'orders_ibfk_1' on table 'Orders'.
mysql> alter table Customers
-> drop zip_code;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc Customers;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| customer_id | int | NO | PRI | NULL | auto_increment |
| first_name | varchar(50) | YES | | NULL | |
| last_name | varchar(50) | YES | | NULL | |
| email | varchar(100) | YES | | NULL | |
| address | varchar(255) | YES | | NULL | |
| city | varchar(100) | YES | | NULL | |
| state | varchar(50) | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)
mysql> alter table Customers
-> add column zip_code int(6);
Query OK, 0 rows affected, 1 warning (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 1
mysql> select *from cutomers;
ERROR 1146 (42S02): Table 'project.cutomers' doesn't exist
mysql> select * from Customers;
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
| customer_id | first_name | last_name | email | address
| city | state | zip_code |
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
| 1 | John | Doe | john.doe@example.com | 123 Main St
| Anytown | CA | NULL |
| 2 | Jane | Smith | jane.smith@example.com | 456 Oak Ave
| Sometown | NY | NULL |
| 3 | Michael | Johnson | michael.johnson@example.com | 789 Elm Rd
| Cityville | TX | NULL |
| 4 | Emily | Lee | emily.lee@example.com | 101 Pine Dr
| Townsville | IL | NULL |
| 5 | William | Wong | william.wong@example.com | 555 Cedar Ln
| Villagetown | FL | NULL |
| 6 | Rahul | Kumar | rahul@example.com | 123 Main St
| Mumbai | MH | NULL |
| 7 | Priya | Sharma | priya@example.com | 456 Park Ave
| Delhi | DL | NULL |
| 8 | Rajesh | Patel | rajesh@example.com | 789 Oak Rd
| Ahmedabad | GJ | NULL |
| 9 | Sanya | Gupta | sanya@example.com | 101 Pine Dr
| Bangalore | KA | NULL |
| 10 | Manish | Singh | manish@example.com | 555 Cedar Ln
| Kolkata | WB | NULL |
| 11 | Neha | Desai | neha@example.com | 888 Maple
Blvd | Chennai | TN | NULL |
| 12 | Ravi | Verma | ravi@example.com | 333 Elm St
| Hyderabad | TS | NULL |
| 13 | Anjali | Reddy | anjali@example.com | 222 Birch
Ave | Pune | MH | NULL |
| 14 | Rohit | Choudhury | rohit@example.com | 777 Oak Rd
| Jaipur | RJ | NULL |
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
14 rows in set (0.00 sec)
mysql> insert into customers(zip_code)
-> values()
-> values()
-> values()
-> values()
-> values()
-> values()
-> values()
-> values()
-> values()
-> values()
-> values()
-> values()
-> values()
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'values()
values()
values()
values()
values()
values()
values()
values()
values()' at line 3
mysql> insert into Customers
-> (zip_code)values(570089);
Query OK, 1 row affected (0.00 sec)
mysql> select * from Customers;
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
| customer_id | first_name | last_name | email | address
| city | state | zip_code |
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
| 1 | John | Doe | john.doe@example.com | 123 Main St
| Anytown | CA | NULL |
| 2 | Jane | Smith | jane.smith@example.com | 456 Oak Ave
| Sometown | NY | NULL |
| 3 | Michael | Johnson | michael.johnson@example.com | 789 Elm Rd
| Cityville | TX | NULL |
| 4 | Emily | Lee | emily.lee@example.com | 101 Pine Dr
| Townsville | IL | NULL |
| 5 | William | Wong | william.wong@example.com | 555 Cedar Ln
| Villagetown | FL | NULL |
| 6 | Rahul | Kumar | rahul@example.com | 123 Main St
| Mumbai | MH | NULL |
| 7 | Priya | Sharma | priya@example.com | 456 Park Ave
| Delhi | DL | NULL |
| 8 | Rajesh | Patel | rajesh@example.com | 789 Oak Rd
| Ahmedabad | GJ | NULL |
| 9 | Sanya | Gupta | sanya@example.com | 101 Pine Dr
| Bangalore | KA | NULL |
| 10 | Manish | Singh | manish@example.com | 555 Cedar Ln
| Kolkata | WB | NULL |
| 11 | Neha | Desai | neha@example.com | 888 Maple
Blvd | Chennai | TN | NULL |
| 12 | Ravi | Verma | ravi@example.com | 333 Elm St
| Hyderabad | TS | NULL |
| 13 | Anjali | Reddy | anjali@example.com | 222 Birch
Ave | Pune | MH | NULL |
| 14 | Rohit | Choudhury | rohit@example.com | 777 Oak Rd
| Jaipur | RJ | NULL |
| 15 | NULL | NULL | NULL | NULL
| NULL | NULL | 570089 |
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
15 rows in set (0.00 sec)
mysql> modify table Customers
-> drop row where customer_id=15;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'modify
table Customers
drop row where customer_id=15' at line 1
mysql> delte from Customers where customer_id=15;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'delte
from Customers where customer_id=15' at line 1
mysql> delete from Customers where customer_id=15;
Query OK, 1 row affected (0.01 sec)
mysql> delete from Customers where customer_id=15;
Query OK, 0 rows affected (0.00 sec)
mysql> desc Customers;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| customer_id | int | NO | PRI | NULL | auto_increment |
| first_name | varchar(50) | YES | | NULL | |
| last_name | varchar(50) | YES | | NULL | |
| email | varchar(100) | YES | | NULL | |
| address | varchar(255) | YES | | NULL | |
| city | varchar(100) | YES | | NULL | |
| state | varchar(50) | YES | | NULL | |
| zip_code | int | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
8 rows in set (0.00 sec)
mysql> select * from Customers;
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
| customer_id | first_name | last_name | email | address
| city | state | zip_code |
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
| 1 | John | Doe | john.doe@example.com | 123 Main St
| Anytown | CA | NULL |
| 2 | Jane | Smith | jane.smith@example.com | 456 Oak Ave
| Sometown | NY | NULL |
| 3 | Michael | Johnson | michael.johnson@example.com | 789 Elm Rd
| Cityville | TX | NULL |
| 4 | Emily | Lee | emily.lee@example.com | 101 Pine Dr
| Townsville | IL | NULL |
| 5 | William | Wong | william.wong@example.com | 555 Cedar Ln
| Villagetown | FL | NULL |
| 6 | Rahul | Kumar | rahul@example.com | 123 Main St
| Mumbai | MH | NULL |
| 7 | Priya | Sharma | priya@example.com | 456 Park Ave
| Delhi | DL | NULL |
| 8 | Rajesh | Patel | rajesh@example.com | 789 Oak Rd
| Ahmedabad | GJ | NULL |
| 9 | Sanya | Gupta | sanya@example.com | 101 Pine Dr
| Bangalore | KA | NULL |
| 10 | Manish | Singh | manish@example.com | 555 Cedar Ln
| Kolkata | WB | NULL |
| 11 | Neha | Desai | neha@example.com | 888 Maple
Blvd | Chennai | TN | NULL |
| 12 | Ravi | Verma | ravi@example.com | 333 Elm St
| Hyderabad | TS | NULL |
| 13 | Anjali | Reddy | anjali@example.com | 222 Birch
Ave | Pune | MH | NULL |
| 14 | Rohit | Choudhury | rohit@example.com | 777 Oak Rd
| Jaipur | RJ | NULL |
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
14 rows in set (0.00 sec)
mysql> modify table Customers
-> set zip_code=570069 where customer_id=1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'modify
table Customers
set zip_code=570069 where customer_id=1' at line 1
mysql> modify Customers set zip_code=570069 where customer_id=1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'modify
Customers set zip_code=570069 where customer_id=1' at line 1
mysql> update Customers set zip_code=570069 where customer_id=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from Customers;
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
| customer_id | first_name | last_name | email | address
| city | state | zip_code |
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
| 1 | John | Doe | john.doe@example.com | 123 Main St
| Anytown | CA | 570069 |
| 2 | Jane | Smith | jane.smith@example.com | 456 Oak Ave
| Sometown | NY | NULL |
| 3 | Michael | Johnson | michael.johnson@example.com | 789 Elm Rd
| Cityville | TX | NULL |
| 4 | Emily | Lee | emily.lee@example.com | 101 Pine Dr
| Townsville | IL | NULL |
| 5 | William | Wong | william.wong@example.com | 555 Cedar Ln
| Villagetown | FL | NULL |
| 6 | Rahul | Kumar | rahul@example.com | 123 Main St
| Mumbai | MH | NULL |
| 7 | Priya | Sharma | priya@example.com | 456 Park Ave
| Delhi | DL | NULL |
| 8 | Rajesh | Patel | rajesh@example.com | 789 Oak Rd
| Ahmedabad | GJ | NULL |
| 9 | Sanya | Gupta | sanya@example.com | 101 Pine Dr
| Bangalore | KA | NULL |
| 10 | Manish | Singh | manish@example.com | 555 Cedar Ln
| Kolkata | WB | NULL |
| 11 | Neha | Desai | neha@example.com | 888 Maple
Blvd | Chennai | TN | NULL |
| 12 | Ravi | Verma | ravi@example.com | 333 Elm St
| Hyderabad | TS | NULL |
| 13 | Anjali | Reddy | anjali@example.com | 222 Birch
Ave | Pune | MH | NULL |
| 14 | Rohit | Choudhury | rohit@example.com | 777 Oak Rd
| Jaipur | RJ | NULL |
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
14 rows in set (0.01 sec)
mysql> update Customers set zip_code=570007 where customer_id=2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update Customers set zip_code=570345 where customer_id=3;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update Customers set zip_code=570045 where customer_id=4;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update Customers set zip_code=570745 where customer_id=5;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update Customers set zip_code=570000 where customer_id=6;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update Customers set zip_code=570035 where customer_id=7;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update Customers set zip_code=570057 where customer_id=8;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update Customers set zip_code=570012 where customer_id=9;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update Customers set zip_code=570007 where customer_id=10;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update Customers set zip_code=570017 where customer_id=11;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update Customers set zip_code=570070 where customer_id=12;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update Customers set zip_code=570071 where customer_id=13;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update Customers set zip_code=570008 where customer_id=14;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from Customers;
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
| customer_id | first_name | last_name | email | address
| city | state | zip_code |
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
| 1 | John | Doe | john.doe@example.com | 123 Main St
| Anytown | CA | 570069 |
| 2 | Jane | Smith | jane.smith@example.com | 456 Oak Ave
| Sometown | NY | 570007 |
| 3 | Michael | Johnson | michael.johnson@example.com | 789 Elm Rd
| Cityville | TX | 570345 |
| 4 | Emily | Lee | emily.lee@example.com | 101 Pine Dr
| Townsville | IL | 570045 |
| 5 | William | Wong | william.wong@example.com | 555 Cedar Ln
| Villagetown | FL | 570745 |
| 6 | Rahul | Kumar | rahul@example.com | 123 Main St
| Mumbai | MH | 570000 |
| 7 | Priya | Sharma | priya@example.com | 456 Park Ave
| Delhi | DL | 570035 |
| 8 | Rajesh | Patel | rajesh@example.com | 789 Oak Rd
| Ahmedabad | GJ | 570057 |
| 9 | Sanya | Gupta | sanya@example.com | 101 Pine Dr
| Bangalore | KA | 570012 |
| 10 | Manish | Singh | manish@example.com | 555 Cedar Ln
| Kolkata | WB | 570007 |
| 11 | Neha | Desai | neha@example.com | 888 Maple
Blvd | Chennai | TN | 570017 |
| 12 | Ravi | Verma | ravi@example.com | 333 Elm St
| Hyderabad | TS | 570070 |
| 13 | Anjali | Reddy | anjali@example.com | 222 Birch
Ave | Pune | MH | 570071 |
| 14 | Rohit | Choudhury | rohit@example.com | 777 Oak Rd
| Jaipur | RJ | 570008 |
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
14 rows in set (0.00 sec)
mysql> select *from products;
+------------+------------+--------
+-----------------------------------------------------+
| product_id | name | price | description
|
+------------+------------+--------
+-----------------------------------------------------+
| 1 | Laptop | 799.99 | High-performance laptop with a sleek design.
|
| 2 | Smartphone | 499.00 | Latest smartphone with advanced features.
|
| 3 | Headphones | 129.95 | Noise-canceling headphones for immersive
audio. |
| 4 | Tablet | 349.50 | Portable tablet with a high-resolution
display. |
| 5 | Camera | 699.00 | Professional DSLR camera for stunning photos.
|
| 6 | Smartwatch | 199.99 | Smartwatch with fitness tracking and
notifications. |
+------------+------------+--------
+-----------------------------------------------------+
6 rows in set (0.00 sec)
mysql> alter table products add rating;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '' at
line 1
mysql> alter table products add column rating;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '' at
line 1
mysql> alter table products add column rating;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '' at
line 1
mysql> alter table products add column rating int(5);
Query OK, 0 rows affected, 1 warning (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 1
mysql> select * from Customers;
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
| customer_id | first_name | last_name | email | address
| city | state | zip_code |
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
| 1 | John | Doe | john.doe@example.com | 123 Main St
| Anytown | CA | 570069 |
| 2 | Jane | Smith | jane.smith@example.com | 456 Oak Ave
| Sometown | NY | 570007 |
| 3 | Michael | Johnson | michael.johnson@example.com | 789 Elm Rd
| Cityville | TX | 570345 |
| 4 | Emily | Lee | emily.lee@example.com | 101 Pine Dr
| Townsville | IL | 570045 |
| 5 | William | Wong | william.wong@example.com | 555 Cedar Ln
| Villagetown | FL | 570745 |
| 6 | Rahul | Kumar | rahul@example.com | 123 Main St
| Mumbai | MH | 570000 |
| 7 | Priya | Sharma | priya@example.com | 456 Park Ave
| Delhi | DL | 570035 |
| 8 | Rajesh | Patel | rajesh@example.com | 789 Oak Rd
| Ahmedabad | GJ | 570057 |
| 9 | Sanya | Gupta | sanya@example.com | 101 Pine Dr
| Bangalore | KA | 570012 |
| 10 | Manish | Singh | manish@example.com | 555 Cedar Ln
| Kolkata | WB | 570007 |
| 11 | Neha | Desai | neha@example.com | 888 Maple
Blvd | Chennai | TN | 570017 |
| 12 | Ravi | Verma | ravi@example.com | 333 Elm St
| Hyderabad | TS | 570070 |
| 13 | Anjali | Reddy | anjali@example.com | 222 Birch
Ave | Pune | MH | 570071 |
| 14 | Rohit | Choudhury | rohit@example.com | 777 Oak Rd
| Jaipur | RJ | 570008 |
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
14 rows in set (0.01 sec)
mysql> select * from Customers;
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
| customer_id | first_name | last_name | email | address
| city | state | zip_code |
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
| 1 | John | Doe | john.doe@example.com | 123 Main St
| Anytown | CA | 570069 |
| 2 | Jane | Smith | jane.smith@example.com | 456 Oak Ave
| Sometown | NY | 570007 |
| 3 | Michael | Johnson | michael.johnson@example.com | 789 Elm Rd
| Cityville | TX | 570345 |
| 4 | Emily | Lee | emily.lee@example.com | 101 Pine Dr
| Townsville | IL | 570045 |
| 5 | William | Wong | william.wong@example.com | 555 Cedar Ln
| Villagetown | FL | 570745 |
| 6 | Rahul | Kumar | rahul@example.com | 123 Main St
| Mumbai | MH | 570000 |
| 7 | Priya | Sharma | priya@example.com | 456 Park Ave
| Delhi | DL | 570035 |
| 8 | Rajesh | Patel | rajesh@example.com | 789 Oak Rd
| Ahmedabad | GJ | 570057 |
| 9 | Sanya | Gupta | sanya@example.com | 101 Pine Dr
| Bangalore | KA | 570012 |
| 10 | Manish | Singh | manish@example.com | 555 Cedar Ln
| Kolkata | WB | 570007 |
| 11 | Neha | Desai | neha@example.com | 888 Maple
Blvd | Chennai | TN | 570017 |
| 12 | Ravi | Verma | ravi@example.com | 333 Elm St
| Hyderabad | TS | 570070 |
| 13 | Anjali | Reddy | anjali@example.com | 222 Birch
Ave | Pune | MH | 570071 |
| 14 | Rohit | Choudhury | rohit@example.com | 777 Oak Rd
| Jaipur | RJ | 570008 |
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
14 rows in set (0.00 sec)
mysql> select * from products;
+------------+------------+--------
+-----------------------------------------------------+--------+
| product_id | name | price | description
| rating |
+------------+------------+--------
+-----------------------------------------------------+--------+
| 1 | Laptop | 799.99 | High-performance laptop with a sleek design.
| NULL |
| 2 | Smartphone | 499.00 | Latest smartphone with advanced features.
| NULL |
| 3 | Headphones | 129.95 | Noise-canceling headphones for immersive
audio. | NULL |
| 4 | Tablet | 349.50 | Portable tablet with a high-resolution
display. | NULL |
| 5 | Camera | 699.00 | Professional DSLR camera for stunning photos.
| NULL |
| 6 | Smartwatch | 199.99 | Smartwatch with fitness tracking and
notifications. | NULL |
+------------+------------+--------
+-----------------------------------------------------+--------+
6 rows in set (0.00 sec)
mysql> update table products set rating=3 where product_id=1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'table
products set rating=3 where product_id=1' at line 1
mysql> update products set rating=3 where product_id=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from products;
+------------+------------+--------
+-----------------------------------------------------+--------+
| product_id | name | price | description
| rating |
+------------+------------+--------
+-----------------------------------------------------+--------+
| 1 | Laptop | 799.99 | High-performance laptop with a sleek design.
| 3 |
| 2 | Smartphone | 499.00 | Latest smartphone with advanced features.
| NULL |
| 3 | Headphones | 129.95 | Noise-canceling headphones for immersive
audio. | NULL |
| 4 | Tablet | 349.50 | Portable tablet with a high-resolution
display. | NULL |
| 5 | Camera | 699.00 | Professional DSLR camera for stunning photos.
| NULL |
| 6 | Smartwatch | 199.99 | Smartwatch with fitness tracking and
notifications. | NULL |
+------------+------------+--------
+-----------------------------------------------------+--------+
6 rows in set (0.00 sec)
mysql> update products set rating=4 where product_id=2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update products set rating=4 where product_id=3;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update products set rating=3 where product_id=4;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update products set rating=5 where product_id=5;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update products set rating=2 where product_id=6;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from products;
+------------+------------+--------
+-----------------------------------------------------+--------+
| product_id | name | price | description
| rating |
+------------+------------+--------
+-----------------------------------------------------+--------+
| 1 | Laptop | 799.99 | High-performance laptop with a sleek design.
| 3 |
| 2 | Smartphone | 499.00 | Latest smartphone with advanced features.
| 4 |
| 3 | Headphones | 129.95 | Noise-canceling headphones for immersive
audio. | 4 |
| 4 | Tablet | 349.50 | Portable tablet with a high-resolution
display. | 3 |
| 5 | Camera | 699.00 | Professional DSLR camera for stunning photos.
| 5 |
| 6 | Smartwatch | 199.99 | Smartwatch with fitness tracking and
notifications. | 2 |
+------------+------------+--------
+-----------------------------------------------------+--------+
6 rows in set (0.00 sec)
mysql> show tables;
+-------------------+
| Tables_in_project |
+-------------------+
| Customers |
| Order_Items |
| Orders |
| products |
+-------------------+
4 rows in set (0.00 sec)
mysql> select * from cutomers where customer_id=(select customer_id from orders
where O;rder_id=(select order_id from Order_Items where ))
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '' at
line 1
-> select * from Orders;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'rder_id=(select order_id from Order_Items where ))
select * from Orders' at line 1
mysql> select * from Orders;
+----------+-------------+------------+--------------+
| order_id | customer_id | order_date | total_amount |
+----------+-------------+------------+--------------+
| 1 | 1 | 2023-07-24 | 1699.97 |
| 2 | 2 | 2023-07-23 | 798.00 |
| 3 | 3 | 2023-07-22 | 977.45 |
| 4 | 4 | 2023-07-21 | 2248.95 |
| 5 | 5 | 2023-07-20 | 499.99 |
+----------+-------------+------------+--------------+
5 rows in set (0.00 sec)
mysql> select * from Order_Items;
+---------------+----------+------------+----------+----------+
| order_item_id | order_id | product_id | quantity | subtotal |
+---------------+----------+------------+----------+----------+
| 1 | 1 | 1 | 2 | 1599.98 |
| 2 | 1 | 3 | 1 | 129.95 |
| 3 | 2 | 2 | 1 | 499.00 |
| 4 | 3 | 4 | 3 | 2098.50 |
| 5 | 4 | 5 | 1 | 699.00 |
| 6 | 5 | 6 | 1 | 199.99 |
+---------------+----------+------------+----------+----------+
6 rows in set (0.00 sec)
mysql> select * from customers;
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
| customer_id | first_name | last_name | email | address
| city | state | zip_code |
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
| 1 | John | Doe | john.doe@example.com | 123 Main St
| Anytown | CA | 570069 |
| 2 | Jane | Smith | jane.smith@example.com | 456 Oak Ave
| Sometown | NY | 570007 |
| 3 | Michael | Johnson | michael.johnson@example.com | 789 Elm Rd
| Cityville | TX | 570345 |
| 4 | Emily | Lee | emily.lee@example.com | 101 Pine Dr
| Townsville | IL | 570045 |
| 5 | William | Wong | william.wong@example.com | 555 Cedar Ln
| Villagetown | FL | 570745 |
| 6 | Rahul | Kumar | rahul@example.com | 123 Main St
| Mumbai | MH | 570000 |
| 7 | Priya | Sharma | priya@example.com | 456 Park Ave
| Delhi | DL | 570035 |
| 8 | Rajesh | Patel | rajesh@example.com | 789 Oak Rd
| Ahmedabad | GJ | 570057 |
| 9 | Sanya | Gupta | sanya@example.com | 101 Pine Dr
| Bangalore | KA | 570012 |
| 10 | Manish | Singh | manish@example.com | 555 Cedar Ln
| Kolkata | WB | 570007 |
| 11 | Neha | Desai | neha@example.com | 888 Maple
Blvd | Chennai | TN | 570017 |
| 12 | Ravi | Verma | ravi@example.com | 333 Elm St
| Hyderabad | TS | 570070 |
| 13 | Anjali | Reddy | anjali@example.com | 222 Birch
Ave | Pune | MH | 570071 |
| 14 | Rohit | Choudhury | rohit@example.com | 777 Oak Rd
| Jaipur | RJ | 570008 |
+-------------+------------+-----------+-----------------------------
+----------------+-------------+-------+----------+
14 rows in set (0.00 sec)
mysql> select * from products;
+------------+------------+--------
+-----------------------------------------------------+--------+
| product_id | name | price | description
| rating |
+------------+------------+--------
+-----------------------------------------------------+--------+
| 1 | Laptop | 799.99 | High-performance laptop with a sleek design.
| 3 |
| 2 | Smartphone | 499.00 | Latest smartphone with advanced features.
| 4 |
| 3 | Headphones | 129.95 | Noise-canceling headphones for immersive
audio. | 4 |
| 4 | Tablet | 349.50 | Portable tablet with a high-resolution
display. | 3 |
| 5 | Camera | 699.00 | Professional DSLR camera for stunning photos.
| 5 |
| 6 | Smartwatch | 199.99 | Smartwatch with fitness tracking and
notifications. | 2 |
+------------+------------+--------
+-----------------------------------------------------+--------+
6 rows in set (0.01 sec)
mysql> select first_name from Customers inner join on Orders;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'on
Orders' at line 1
mysql> select c.first_name from Customers c inner join Orders o where o.customer_id
= c.customer_id;
+------------+
| first_name |
+------------+
| John |
| Jane |
| Michael |
| Emily |
| William |
+------------+
5 rows in set (0.00 sec)
mysql> select * from orders;
+----------+-------------+------------+--------------+
| order_id | customer_id | order_date | total_amount |
+----------+-------------+------------+--------------+
| 1 | 1 | 2023-07-24 | 1699.97 |
| 2 | 2 | 2023-07-23 | 798.00 |
| 3 | 3 | 2023-07-22 | 977.45 |
| 4 | 4 | 2023-07-21 | 2248.95 |
| 5 | 5 | 2023-07-20 | 499.99 |
+----------+-------------+------------+--------------+
5 rows in set (0.00 sec)
mysql> select * from Order_items;
+---------------+----------+------------+----------+----------+
| order_item_id | order_id | product_id | quantity | subtotal |
+---------------+----------+------------+----------+----------+
| 1 | 1 | 1 | 2 | 1599.98 |
| 2 | 1 | 3 | 1 | 129.95 |
| 3 | 2 | 2 | 1 | 499.00 |
| 4 | 3 | 4 | 3 | 2098.50 |
| 5 | 4 | 5 | 1 | 699.00 |
| 6 | 5 | 6 | 1 | 199.99 |
+---------------+----------+------------+----------+----------+
6 rows in set (0.00 sec)
mysql> select select * from Customers where (select Order_id from Orders where
(select Order_id from Order_items where product_id = 1));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'select *
from Customers where (select Order_id from Orders where (select Order_i' at line 1
mysql> select * from Customers where (select Order_id from Orders where (select
Order_id from Order_items where product_id = 1));
ERROR 1242 (21000): Subquery returns more than 1 row
mysql> select first_name from Customers where (select Order_id from Orders where
(select Order_id from Order_items where product_id
= 1));
ERROR 1242 (21000): Subquery returns more than 1 row
mysql> select first_name from Customers where customer_id = (select Customer_id
from Orders where order_id = (select Order_id from O
rder_items where product_id = 1));
+------------+
| first_name |
+------------+
| John |
+------------+
1 row in set (0.01 sec)
mysql> select * from Customers where customer_id = (select Customer_id from Orders
where order_id = (select Order_id from Order_items where product_id = 1));
+-------------+------------+-----------+----------------------+-------------
+---------+-------+----------+
| customer_id | first_name | last_name | email | address | city
| state | zip_code |
+-------------+------------+-----------+----------------------+-------------
+---------+-------+----------+
| 1 | John | Doe | john.doe@example.com | 123 Main St |
Anytown | CA | 570069 |
+-------------+------------+-----------+----------------------+-------------
+---------+-------+----------+
1 row in set (0.00 sec)
mysql> SELECT c.customer_id, c.first_name, c.last_name, p.name AS product_name
-> FROM Customers c
-> JOIN Orders o ON c.customer_id = o.customer_id
-> JOIN Order_Items oi ON o.order_id = oi.order_id
-> JOIN Products p ON oi.product_id = p.product_id;
+-------------+------------+-----------+--------------+
| customer_id | first_name | last_name | product_name |
+-------------+------------+-----------+--------------+
| 1 | John | Doe | Laptop |
| 1 | John | Doe | Headphones |
| 2 | Jane | Smith | Smartphone |
| 3 | Michael | Johnson | Tablet |
| 4 | Emily | Lee | Camera |
| 5 | William | Wong | Smartwatch |
+-------------+------------+-----------+--------------+
6 rows in set (0.01 sec)
mysql> select * from Orders order by Order_date limit 1;
+----------+-------------+------------+--------------+
| order_id | customer_id | order_date | total_amount |
+----------+-------------+------------+--------------+
| 5 | 5 | 2023-07-20 | 499.99 |
+----------+-------------+------------+--------------+
1 row in set (0.00 sec)
mysql> sect * from customers where customer_id=(select ccustomer_id from orders
order by order_date limit=1);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'sect *
from customers where customer_id=(select ccustomer_id from orders order b' at line
1
mysql> sect * from customers where customer_id=(select customer_id from orders
order by order_date limit=1);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'sect *
from customers where customer_id=(select customer_id from orders order by' at line
1
mysql> sect * from Customers where customer_id=(select customer_id from Orders
order by Order_date limit=1);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'sect *
from Customers where customer_id=(select customer_id from Orders order by' at line
1
mysql>