SQL for Beginners - Full Notes
SQL for Beginners - Full Notes
SQL for Beginners - Database Concepts (Database, DBMS, Data Models, RDBMS and SQL)
In-order to understand SQL, we have to first understand different Database Concepts like:
Database
DBMS
Data Models
RDBS
SQL etc.
Database Concepts:
Databases
The place we can store the related data and later retrieve the data is known as Database
Storing the related Data like Employee ID, Employee Name, Employee Salary, Department
etc. can be stored
Retrieving the data based on some conditions
Database Management Systems
Shortly called as DBMS
Software that stores data in databases in an organized way to make it easier to create, retrieve,
update etc.
Examples: DBase, FoxPro, MySQL, Oracle, MangoDB, MariaDB, SQLite, Cassandra and many more
Data Models
Defines how related data is connected to each other and stored inside the database.
Types of Data Models:
Hierarchical Model
Network Model
Entity-Relationship Model
Relational Model
Data is stored in the form of tables
Tables organize the data in the form of rows and columns
It is a popular and widely used by most of the DBMS Software
RDBMS
DBMS using Relational Data Models are known as RDBMS
Examples for RDBMS Software:
1. Oracle
2. MS-SQL Server
3. DB2
4. MySQL
5. MS-ACCESS
6. etc.
SQL
Programming language for Relational Databases
Stands for Structured Query Language
The following things can be performed on Database using SQL:
Inserting Data
Retrieving Data
Updating Data
Deleting Data
And many more
file:///D:/QAFox/Youtube/SQL for Beginners/Part 1/SQL for Beginners - Part 1 - Database Concepts (Database, DBMS, Data Models, RDBMS an… 1/1
01/11/2020 Evernote Export
1. Kick start learning or practicing SQL without installing any RDBMS software
2. Google Search for 'W3Schools Try SQL'
3. We don't need to create any DB or tables to get started
1. Existing tables with the required data is in place
4. Start by Restoring the Database
1. If we lose any data by our operations and want it back, we can restore it
5. Executing a sample SQL statement
1. Select * from Customers;
file:///D:/QAFox/Youtube/SQL for Beginners/Part 2/SQL for Beginners - Part 2 - Practice SQL without installing any Software.html 1/1
01/11/2020 Evernote Export
1. The purpose this SQL command is to retrieve the data from the tables
2. Retrieving all the data from Customers table
1. Syntax: Select * from TableName;
2. Select * from Customers;
3. Retrieving specific column data from Customers table
1. Select CustomerName from Customers;
2. Select CustomerName,Country,City,PostalCode from Customers;
Regards,
Arun Motoori
QAFox.com
file:///D:/QAFox/Youtube/SQL for Beginners/Part 3/SQL for Beginners - Part 3 - Select Command.html 1/1
01/11/2020 Evernote Export
1. For unique values to be retrieved, we have to use distinct keyword with Select command
2. Without distinct:
1. Select Country from Customers;
3. With distinct:
1. Select distinct Country from Customers;
2. Select distinct Country,PostalCode from Customers;
1. Combination of Country and PostalCode should be unique
Regards,
Arun Motoori
QAFox.com
file:///D:/QAFox/Youtube/SQL for Beginners/Part 4/SQL for Beginners - Part 4 - distinct keyword.html 1/1
01/11/2020 Evernote Export
1. All the below statements will work same irrespective of their case
Select CustomerName,PostalCode from Customers;
select customername,postalcode from customers;
SELECT CUSTOMERNAME,POSTALCODE FROM CUSTOMERS;
Regards,
Arun Motoori
QAFox.com
file:///D:/QAFox/Youtube/SQL for Beginners/Part 5/SQL for Beginners - Part 5 - SQL is not case sensitive.html 1/1
01/11/2020 Evernote Export
Regards,
Arun Motoori
QAFox.com
Regards,
Arun Motoori
QAFox.com
file:///D:/QAFox/Youtube/SQL for Beginners/Part 7/SQL for Beginners - Part 7 - Where Clause.html 1/1
01/11/2020 Evernote Export
Regards,
Arun Motoori
QAFox.com
file:///D:/QAFox/Youtube/SQL for Beginners/Part 8/SQL for Beginners - Part 8 - Using Relational Operators in Where Clause Condition.html 1/1
01/11/2020 Evernote Export
By,
Arun Motoori
QAFox.com
file:///D:/QAFox/Youtube/SQL for Beginners/Part 9/SQL for Beginners - Part 9 - Using Logical Operators (AND, OR, NOT).html 1/1
01/11/2020 Evernote Export
Regards,
Arun Motoori
QAFox.com
file:///D:/QAFox/Youtube/SQL for Beginners/Part 10/SQL for Beginners - Part 10 - Between Operator.html 1/1
2/8/23, 12:18 PM SQL for Beginners - Part 11 - Order By Clause (ASC, DESC)
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=c36c7c1f-bc7a-4bcd-83ab-7815c382015a¬eKey=7b7a3c1ddab6af1b&sn=https%3… 1/1
2/8/23, 12:22 PM SQL for Beginners - Part 12 - Using Between Operator with Text
1. In one the previous video, I have explained how to use Between operator with Numbers
2. Practical Demonstration:
1. Select * from Customers;
2. Select * from Customers Order By Country;
3. Select * from Customers where Country Between 'Canada' And 'Finland' Order By
Country;
4. Select * from Customers where Country NOT Between 'Canada' And 'Finland' Order By
Country;
Regards,
Arun Motoori
https://www.evernote.com/shard/s433/client/snv?noteGuid=f66eb57b-b26a-4127-858f-72cd942d37c3¬eKey=b1b5a90053c68442&sn=https%… 1/1
2/8/23, 12:23 PM SQL for Beginners - Part 13 - In Operator
1. Simplifies providing multiple values in Where Clause, when all the values are from the same
column
2. Practical Demonstration:
1. Select * from Products;
2. Select * from Products where Price=18 OR Price=30 OR Price=10;
3. Select * from Products where Price in (18,30,10);
4. Select * from Customers;
5. Select * from Customers where Country='USA' OR Country='Canada' OR
Country='UK';
6. Select * from Customers where Country in ('USA','Canada','UK');
Regards,
Arun Motoori
https://www.evernote.com/shard/s433/client/snv?noteGuid=c2d4a669-2e7d-4e0f-80b4-79b14716357a¬eKey=7f83147f54ac7314&sn=https%3… 1/1
2/8/23, 12:24 PM SQL for Beginners - Part 14 - Like Operator and Wildcard Characters
1. We can use Like Operator and Wildcard Characters for Pattern matching needs
2. We can use them in the Where Clause Conditions
3. Practical Demonstration:
1. Select * from Customers;
2. Select * from Customers Where Country Like '%a';
3. Select * from Customers Where Country Like 'F%';
4. Select * from Customers Where Country Like 'G%Y';
5. Select * from Customers where Country like 'Mex%';
6. Select * from Customers where country like '%nez%';
7. Select * from Customers where country like '%Can%';
8. Select * from Customers where country like '_weden';
9. Select * from Customers where country like 'U_';
10. Select * from Customers where country like '__A';
11. Select * from Customers where country like 'M_x_c_';
12. Select * from Customers where Country like 'Fin_a%';
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=1fc47f43-5844-4759-838d-e159299d0546¬eKey=79cd69489f6a16a1&sn=https%3… 1/1
2/8/23, 12:25 PM SQL for Beginners - Part 15 - Aliases for Table Column Names (AS Keyword)
1. While the records are retrieved these alias names provided for Column names will be
displayed temporary in place of Original Column names
2. Practical Demonstration:
1. Select * from Categories;
2. Select CategoryID,CategoryName from Categories;
3. Select CategoryID as ID,CategoryName as Name from Categories;
4. As is optional - Select CategoryID ID,CategoryName Name from Categories;
5. Select CategoryID as [Category ID],CategoryName as [Category Name] from
Categories;
Regards,
Arun Motoori
https://www.evernote.com/shard/s433/client/snv?noteGuid=b8f9b7f5-32de-4509-b4e4-b41c446f4b42¬eKey=f463de0a3e25264b&sn=https%3… 1/1
2/8/23, 12:26 PM SQL for Beginners - Part 16 - Limit Keyword
1. When a Table has 1000's of records, the Application will slow down when trying to display
them.
2. Using Limit keyword we can decide how many records needs to be displayed on the page
irrespective of number of records available, there by improving the performance
3. Practical Demonstration:
1. Select * from Customers;
2. Select * from Customers Limit 3;
3. Select * from Customers where Country='USA';
4. Select * from Customers where Country='USA' Limit 5;
5. Select * from Customers Limit 2,6;
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=efc237f7-abc9-46cc-888d-80eaa848efb9¬eKey=997742c273f77ca0&sn=https%3A… 1/1
2/8/23, 12:27 PM SQL for Beginners - Part 17 - Breaking the Lengthy SQL Statement into multiple lines
1. We can break the lengthy SQL statement into multiple lines for better understanding
2. Practical Demonstration
1. Select * from Customers;
2. Select CustomerID,CustomerName,Country,City from Customers where
Country='France';
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=c964c5e1-4837-482a-b706-b8180cfc86e7¬eKey=7c95aff91834b7f6&sn=https%3… 1/1
2/8/23, 12:29 PM SQL for Beginners - Part 18 - MySQL Built-in Functions
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=3e60f5dd-d2cd-46ef-85c5-29e71777e25a¬eKey=2de50199ccc5f13e&sn=https%3… 1/1
2/8/23, 12:29 PM SQL for Beginners - Part 19 - upper() MySQL String Function
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=22427ad1-a190-406c-8fa4-65ada2d7a12d¬eKey=b0af4717d09a2317&sn=https%… 1/1
2/8/23, 12:30 PM SQL for Beginners - Part 20 - lower() MySQL String Function
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=14ca7694-7053-4c52-9097-06318fb4e1b3¬eKey=aeea57f1b0b68f3d&sn=https%3… 1/1
2/8/23, 12:32 PM SQL for Beginners - Part 21 - length() MySQL String Function
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=642010d5-866b-4d6a-94fd-9a1a1e965d92¬eKey=be7236657c3bc223&sn=https%… 1/1
2/8/23, 12:33 PM SQL for Beginners - Part 22 - instr() MySQL String Function
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=3513365a-542a-4fdd-814d-517d4ed63d44¬eKey=1956e3066a526fde&sn=https%… 1/1
2/8/23, 12:36 PM SQL for Beginners - Part 23 - substr() MySQL String Function
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=a4368566-bbb3-4323-80d6-caac0d4c613b¬eKey=6387c9818a71f0ac&sn=https%… 1/1
2/8/23, 12:36 PM SQL for Beginners - Part 24 - concat() MySQL String Function
Regards,
Arun Motoori
https://www.evernote.com/shard/s433/client/snv?noteGuid=b3761336-924e-4ac6-8946-6b9e76deb9ef¬eKey=7a28502e434f2707&sn=https%… 1/1
2/8/23, 12:37 PM SQL for Beginners - Part 25 - trim() MySQL String Function
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=8f45d8f0-3143-4b13-a869-22729b36d151¬eKey=0e44fee044c7f91a&sn=https%3… 1/1
2/8/23, 12:38 PM SQL for Beginners - Part 26 - abs() MySQL Numeric Function
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=24a2c092-ec32-4bd6-bd03-01fd30c5e5bd¬eKey=357d96b0e516c95b&sn=https%… 1/1
2/8/23, 12:39 PM SQL for Beginners - Part 27 - mod() MySQL Numeric Function
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=30eab84f-6cf7-46ec-a9da-8ef4da13286e¬eKey=4dbbf91df3dac566&sn=https%3A… 1/1
2/8/23, 12:39 PM SQL for Beginners - Part 28 - greatest() and least() MySQL Numeric Functions
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=e3e9e6d5-b51b-44fa-9c3a-992d56989fe8¬eKey=889831d0346855c2&sn=https%… 1/1
2/8/23, 12:41 PM SQL for Beginners - Part 29 - truncate() MySQL Numeric Function
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=03544e49-5249-47a3-9afd-c829920a4844¬eKey=261f9d9f9e3a2a13&sn=https%3… 1/1
2/8/23, 12:43 PM SQL for Beginners - Part 30 - power() and sqrt() MySQL Numeric Functions
1. Practical Demonstration
1. Select power(3,4);
2. Select sqrt(2);
2. Many other MySQL Numeric Functions
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=9177d32f-50a9-42ff-824a-f2188eec4816¬eKey=8c5497e267673460&sn=https%3… 1/1
2/8/23, 12:44 PM SQL for Beginners - Part 31 - current_date(), curdate(), current_time(), curtime(), now() and sysdate() MySQL Date Time Fun…
1. Practical Demonstration
1. Select current_date();
2. Select curdate();
3. Select current_time();
4. Select curtime();
5. select now();
6. select sysdate();
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=3beae38f-ed43-4247-8f9e-b26053d481f4¬eKey=5ca635b2d77b04c6&sn=https%3… 1/1
2/8/23, 12:44 PM SQL for Beginners - Part 32 - year(),month(),day,monthname(),dayname() MySQL Date Time Functions
1. Practical Demonstration
1. Select year('2020-04-25');
2. Select month('2020-04-25');
3. Select day('2020-04-25');
4. Select monthname('2020-04-25');
5. Select dayname('2020-04-25');
6. SELECT * FROM Orders where month(OrderDate)=4;
7. SELECT * FROM Orders where monthname(OrderDate)='May';
2. Many more Date and Time functions
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=2ddfabfa-8220-4cd0-9c4d-2ae76be88339¬eKey=1c8f915aa9c132c9&sn=https%3… 1/1
2/8/23, 12:45 PM SQL for Beginners - Part 33 - avg(), max(), min(), count() and sum() MySQL Aggregate Functions
1. Practical Demonstration
1. Select avg(price) from Products;
2. Select min(price) from Products;
3. Select max(price) from Products;
4. Select count(*) from Products;
5. Select sum(price) from Products;
2. Many more Aggregate functions
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=1692d655-b964-4e22-81a3-430966a8a85d¬eKey=f796b4539036f5bb&sn=https%… 1/1
2/8/23, 12:45 PM SQL for Beginners - Part 34 - Arithmetic Operators
1. The below are the different Arithmetic Operators we can use in the SQL Statements:
1. Addition (+)
2. Subtraction (-)
3. Multiplication (*)
4. Division (/)
5. Modulus (%)
2. Practical Demonstration:
1. Select 5+4;
2. Select 5-4;
3. Select 5*4;
4. Select 5/4;
5. Select 5%4;
6. Select Price, Price+10 from Products;
7. Select Price, Price - 10 from Products;
8. Select Price, Price * 10 from Products;
9. Select Price, Price / 10 from Products;
10. Select Price, Price % 10 from Products;
Regards,
Arun Motoori
QAFox.co
https://www.evernote.com/shard/s433/client/snv?noteGuid=8ca00980-3b6f-4ffe-8a93-731b24cd17ac¬eKey=34b03de5c2c1c09e&sn=https%3… 1/1
2/8/23, 12:46 PM SQL for Beginners - Part 35 - Installing MySQL Server and Workbench Client for Practising SQL
1. Database Components
1. Client - Runs the SQL queries and communicates with the Server
1. Generally installed in the Local machines
2. Server - Stores the Data into DB
1. Generally installed in Remote Server Machine
2. So far we have practiced SQL statements on the DB hosted by W3Schools
3. Now, lets install our own DB in our machine for practicing SQL from Scratch
4. There are several RDBMS Software available in the market and MySQL is an open source and
available for free of cost.
5. Installing MySQL RDBMS Software, will install both Client and Server
6. The below are the steps for installing MySQL Server and Workbench Client Software:
1. Installing MySQL on Windows
1. Google Search for 'download mysql on windows'
2. Click on this link 'https://dev.mysql.com/downloads/mysql/" from the search
results
3. Click on 'Go to Downloader Page'
4. Select to download the 'mysql-installer-community-Version.msi'
5. Login or Register to Download
6. Click on 'Download Now' button
7. Click on 'Next' when the 'Custom' option is selected
8. Move MySQL Server and MySQL Workbench (From Available products to
Products to be installed)
9. Click on 'Next' until you reach 'Accounts and Roles' screen
10. Give root and root as password and repeat password
11. Click on 'Add User' button
12. Give admin and admin as username and password
13. Click 'ok' and click on 'Next' button
14. Click on 'Next' button until you see 'Execute' button
15. Click on 'Execute' button
16. Click on 'Finish' button
17. Click on 'Next' and 'Finish' buttons until it asks for password
18. Click on 'Next' and 'Finish' and observe that the MySQL Workbench will open
2. Using GUI version of Client - MySQL Workbench
1 Search for Workbench in indo s and open the Soft are
https://www.evernote.com/shard/s433/client/snv?noteGuid=252801b7-2afb-4602-9c7a-d3da7ffad12f¬eKey=4dc4bebc1ffb41fa&sn=https%3A… 1/2
2/8/23, 12:46 PM SQL for Beginners - Part 35 - Installing MySQL Server and Workbench Client for Practising SQL
1. Search for Workbench in windows and open the Software
2. Select Database
Terms > ManagePrivacy
of Service Connections
Policy Report SpamSave Copy to Evernote
3. Select Local Instance and change the name to your desired name say
'MySQL_Server', test and close
4. Select Database > Connect to Database
5. Click on 'Ok'
6. Click on 'Schemas' tab in the displayed window and observe that it will show
you all the databases already created
7. We can expand these Databases and see what is inside
8. In order to see the data inside any Table, right click on the table and select
https://www.evernote.com/shard/s433/client/snv?noteGuid=252801b7-2afb-4602-9c7a-d3da7ffad12f¬eKey=4dc4bebc1ffb41fa&sn=https%3A… 2/2
2/8/23, 12:47 PM SQL for Beginners - Part 36 - Creating, Deleting, viewing and using Databases
1. Practical Demonstration
1. Show Databases;
2. Create Database TestDB;
3. Refresh to see the Database Reflected
4. Observe that the DB will be created without any below objects:
1. Tables
2. Views
3. Stored Procedures
4. etc.
5. Drop Database TestDB;
6. Refresh to see the Database deleted
7. Create Database QAFox
8. Select * from actor;
9. Select * from sakila.actor;
10. Use sakila;
11. Select * from actor;
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=93fe6c0a-5f43-45a2-a953-d1666bb5ac0d¬eKey=1c8d74a33c0b5e56&sn=https%3… 1/1
2/8/23, 12:47 PM SQL for Beginners - Part 37 - Creating,Viewing, Describing and Deleting Tables
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=30892776-e40b-4e53-89d1-fd65341ca40a¬eKey=4dd378756e7c39c3&sn=https%… 1/1
2/8/23, 12:48 PM SQL for Beginners - Part 38 - Insert Into Statements (For inserting data into Tables)
1. Practical Demonstration
1. use qafox;
2. show tables;
3. Select * from employees;
4. Describe employees;
5. insert into employees values(1,'Arun',12);
6. Select * from employees;
7. insert into employees values(2,'Varun',5);
8. Select * from employees;
9. insert into employees values(3,'Tharun',7);
10. Select * from employees;
11. insert into employees values(4,'Alice');
1. Will get an error
12. insert into employees(id,name) values(4,'Alice');
1. Null value will be inserted in place on non-inserted column
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=9a47757d-0c80-4f7f-8ee0-d0d5672babc9¬eKey=ecfd08fe92afa2f5&sn=https%3A… 1/1
2/8/23, 12:48 PM SQL for Beginners - Part 39 - Data Types
Regards,
Arun Motoori
https://www.evernote.com/shard/s433/client/snv?noteGuid=7f65c5b3-d13c-49e5-8daf-660b4ad49e42¬eKey=40a27fcac7a8e5d7&sn=https%3… 2/2
2/8/23, 12:48 PM SQL for Beginners - Part 40 - Null Value, Is Null Operator and Is Not Null Operator
1. Practical Demonstration
1. use qafox;
2. show tables;
3. select * from employees;
4. insert into Employees values(5,'Kiran');
1. Error
5. insert into Employees(id,name) values(5,'Kiran');
6. select * from employees;
7. Select * from employees where experience IS NULL;
8. Select * from employees where experience IS NOT NULL;
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=fb38fa2e-84a5-4325-a1a4-b45044b0309d¬eKey=4b733176d711c57f&sn=https%3… 1/1
2/8/23, 12:49 PM SQL for Beginners - Part 41 - Delete Statement (For Deleting the Records from Table)
1. Practical Demonstration
1. use qafox;
2. select * from employees;
3. delete from employees where id=5;
4. delete from employees where name='Tharun';
5. delete from employees;
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=ef23b69b-64fc-40a0-bd82-dccb9eaa2e7d¬eKey=80269e8f4b758f9c&sn=https%3… 1/1
2/8/23, 12:49 PM SQL for Beginners - Part 42 - Update Statement and Set Keyword (For Updating the Table Records)
1. Practical Demonstration
1. use qafox;
2. select * from employees;
3. insert into employees values(1,'Arun',12);
4. insert into employees values(2,'Varun',5);
5. insert into employees values(3,'Tharun',7);
6. update employees set name='Kiran' where id=3;
7. update employees set name='Tharun',id=4 where experience=5;
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=e9eeffd6-808a-40f9-b39a-fe402bbae68c¬eKey=3adf86403fe3132e&sn=https%3A… 1/1
2/8/23, 12:49 PM SQL for Beginners - Part 43 - Rename statement and To Keyword (For Renaming Table Name)
1. Practical Demonstration
1. use qafox;
2. show tables;
3. rename table employees to emp;
4. rename table emp to employees;
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=161a432b-bef3-4188-b845-23c2e386a21d¬eKey=54d8e8d4102dd538&sn=https%… 1/1
2/8/23, 12:49 PM SQL for Beginners - Part 44 - Alter Statement, Add, Modify Column, Rename Column and Drop Column Keywords
1. Practical Demonstration
1. use qafox;
2. show tables;
3. describe employees;
4. alter table employees add location varchar(15);
5. describe employees;
6. alter table employees modify column location varchar(20);
7. describe employees;
8. alter table employees rename column location to loc;
9. describe employees;
10. alter table employees drop column loc;
11. describe employees;
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=f8d11b25-3c8e-4ad7-bafd-9611aaa2b0bc¬eKey=044f17e424e8668f&sn=https%3… 1/1
2/8/23, 12:50 PM SQL for Beginners - Part 45 - Set Autocommit
1. Practical Demonstration
1. use qafox;
2. show tables;
3. Select * from employees;
4. insert into employees values(9,'Dinesh',3);
5. Select * from employees;
6. Restart the workbench client and observe that the inserted data is stored
1. use qafox;
2. Select * from employees;
7. set autocommit=0;
8. insert into employees values(11,'Isha',6);
9. Select * from employees;
10. Restart the workbench client and observe that the inserted data is not stored
1. use qafox;
2. Select * from employees;
11. set autocommit=1;
12. insert into employees values(11,'Isha',6);
13. Select * from employees;
14. Restart the workbench client and observe that the inserted data is stored
1. use qafox;
2. Select * from employees;
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=eb6a17ea-71cd-47df-a7e1-b4c660494e74¬eKey=2a6d2ce8cd4afac7&sn=https%3… 1/1
2/8/23, 12:50 PM SQL for Beginners - Part 46 - Commit Statement
1. Practical Demonstration
1. use qafox;
2. show tables;
3. set autocommit=0;
4. Select * from employees;
5. insert into employees values(9,'Dinesh',3);
6. Select * from employees;
7. Restart the workbench client and observe that the inserted data is not permanently
stored
1. use qafox;
2. Select * from employees;
8. insert into employees values(9,'Dinesh',3);
9. commit;
10. Select * from employees;
11. Restart the workbench client and observe that the inserted data is stored permanently
1. use qafox;
2. Select * from employees;
12. set autocommit=1;
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=39fcbd23-8991-41e2-841f-7eda3e18078c¬eKey=8012cf1b2f4af150&sn=https%3A… 1/1
2/8/23, 12:50 PM SQL for Beginners - Part 47 - Rollback Statement
1. Practical Demonstration
1. use qafox;
2. show tables;
3. set autocommit=0;
4. Select * from employees;
5. delete from employees;
6. Select * from employees;
7. rollback;
8. delete from employees;
9. commit;
10. rollback;
11. set autocommit=1;
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=ece0c920-48e3-46c0-9bc8-953c628e44e6¬eKey=ac45ecea68bc0232&sn=https%… 1/1
2/8/23, 12:51 PM SQL for Beginners - Part 48 - Truncate Statement
1. Practical Demonstration
1. use qafox;
2. show tables;
3. Select * from employees;
4. insert into employees values(1,'Arun',12);
5. commit;
6. set autocommit=0;
7. delete from employees;
8. rollback;
9. Select * from employees;
10. truncate table employees;
11. rollback;
12. Select * from employees;
13. set autocommit=1;
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=0a9a081c-e8e9-4999-af62-cc2cd13f25ee¬eKey=519410e1c6c7e468&sn=https%3… 1/1
2/8/23, 12:51 PM SQL for Beginners - Part 49 - Single Line and Multi-Line Comments
1. Comments are the Statements which won't be executed like general SQL statements
2. Can be used for any of the below reasons:
1. To explain the underlying statements to make it understandable
2. To hide the statement from execution
3. Types of Comments in SQL
1. Single Line Comments
2. Multi-Line Comments
4. Practical Demonstration
1. -- The below SQL statement is used for selecting the Database for further operations
2. use qafox;
3. /* The below SQL statements are used for finding the list of tables in the above
selected
4. database and to retrieve the records from the specified table */
5. show tables;
6. select * from employees;
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=921f4d2a-19bd-4ff6-9631-64c1b4ef3380¬eKey=b1be0a5384992549&sn=https%3… 1/1
2/8/23, 12:51 PM SQL for Beginners - Part 50 - Group By Clause
1. Practical Demonstration
1. use world;
2. show tables;
3. select * from country;
4. Select name from country;
5. select count(Name) from country;
6. select count(name) from country group by Continent;
7. select continent,count(name) from country group by Continent;
By,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=cd656490-4664-4cc6-b5c5-c2e6ffdf0a60¬eKey=206f86d9743573ba&sn=https%3… 1/1
2/8/23, 12:51 PM SQL for Beginners - Part 51 - Having Clause
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=259ece99-c4bb-4902-92c7-e693e002aa87¬eKey=fd6a06c730792e8e&sn=https%… 1/1
2/8/23, 12:52 PM SQL for Beginners - Part 52 - Sequence of using where, group by, having and order by clauses
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=71016c16-4f04-4e91-8523-4a5349f2d85d¬eKey=ba97f0aa9aaba519&sn=https%3… 1/1
2/8/23, 12:52 PM SQL for Beginners - Part 53 - Set Operators
1. We can retrieve the data from different tables at a time using the Set Operators
1. Select * from TableOne Set Operator Select * from TableTwo;
2. The below are the different Set Operators
1. Union
2. Union All
3. Intersect
4. Minus
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=b7f193cc-733c-4d3e-8ac9-cedc7c0b0d0c¬eKey=6a1ecabefbc511e5&sn=https%3… 1/1
2/8/23, 12:54 PM SQL for Beginners - Part 54 - Union Operator
Regards
https://www.evernote.com/shard/s433/client/snv?noteGuid=77116281-1cbc-4a3a-919a-6164f0dcecc2¬eKey=cbecfd6217f3f480&sn=https%3A… 1/1
2/8/23, 12:54 PM SQL for Beginners - Part 55 - Union All Operator
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=2a58b741-461b-4e34-a1d1-66e507b5a2f2¬eKey=1c478ec62ff59686&sn=https%3… 1/1
2/8/23, 12:55 PM SQL for Beginners - Part 56 - Intersect Operator
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=584c96bb-6e82-4653-b4ad-a01bc4f54dda¬eKey=aedf31eab7c7f671&sn=https%3… 1/1
2/8/23, 12:55 PM SQL for Beginners - Part 57 - Minus Operator
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=93ebdd10-2f09-4034-8841-71ac5b7b2e6e¬eKey=96df486bc0b44243&sn=https%… 1/1
2/8/23, 12:55 PM SQL for Beginners - Part 58 - Tables and Aliases
1. Practical Demonstration
1. Select o.id,o.firstname,t.lastname
2. from empdetailsone o,empdetailstwo t
3. where o.id=t.id;
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=4e9faf6c-dfa6-4a9d-8394-edc8db92fb95¬eKey=74bb0467410268de&sn=https%3… 1/1
2/8/23, 12:56 PM SQL for Beginners - Part 59 - Joins (Inner Join, Left Join, Right Join, Full Join and Self Join)
1. The purpose of the Joins is to Join two tables while retrieving the records using the common
column
2. The two tables should have a common column
3. Types of Joins:
1. Inner Join (Equi Join or Simple Join)
2. Left Join (Left Outer Join)
3. Right Join (Right Outer Join)
4. Full Join (Full Outer Join) - Not supported by MySQL
5. Self Join
4. Practical Demonstrations
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=fe3281a0-5ce5-4aba-8171-d4b498cea381¬eKey=dbc9939bc21866b8&sn=https%… 1/1
2/8/23, 12:57 PM SQL for Beginners - Part 60 - Sub Query (Explaining Single Row Sub Query by solving different SQL problems)
https://www.evernote.com/shard/s433/client/snv?noteGuid=0a3f9988-7de9-4ca8-b392-93484c7be4a1¬eKey=9b97a7e80ac8de3f&sn=https%… 2/2
2/8/23, 12:58 PM SQL for Beginners - Part 61 - In Operator
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=237b6be4-5453-499a-bdc2-5467efd5d77e¬eKey=6d0445c4a183c3c2&sn=https%… 1/1
2/8/23, 12:58 PM SQL for Beginners - Part 62 - Using In Operator with Multi Row Sub Query
1. Multi Row Sub Query is a Query inside another Query and it provides multi records as input
to the outer query
2. Different Operators which can be used in Multi Row Sub Query
1. in
2. any
3. all
4. exists
3. Practical Demonstration
1. Find the different Products from the specified Categories
1. Select * from Products where CategoryID in (Select CategoryID from Categories
where CategoryName like 'c%');
Regards,
Arun Motoori
https://www.evernote.com/shard/s433/client/snv?noteGuid=ac6d3579-0a60-4e9d-abb6-3716fdcef1a8¬eKey=107e2d6e73a7c89e&sn=https%… 1/1
2/8/23, 12:58 PM SQL for Beginners - Part 63 - Using Any Operator in Multi Row Sub Query
1. Multi Row Sub Query is a Query inside another Query and it provides multi records as input
to the outer query
2. Different Operators which can be used in Multi Row Sub Query
1. in
2. any
3. all
3. Practical Demonstration
1. Select * from Products where ProductID < any (SELECT ProductID FROM OrderDetails
where Quantity=1);
Regards,
Arun Motoori
https://www.evernote.com/shard/s433/client/snv?noteGuid=8b566e8f-0217-4e8c-9b1d-f56a3986f5f6¬eKey=9fd93cfeffff9d19&sn=https%3A%2… 1/1
2/8/23, 12:59 PM SQL for Beginners - Part 64 - Using All Operator in Multi Row Sub Query
1. Practical Demonstration
1. Select * from Products where ProductID < all (SELECT ProductID FROM OrderDetails
where Quantity=1);
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=2ae38846-d16a-442e-8438-74c97a84bafc¬eKey=1ec8d96e2c8414b8&sn=https%… 1/1
2/8/23, 12:59 PM SQL for Beginners - Part 65 - Exists Operator
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=4f946882-cddb-4cbb-81d4-58801e4d0e3d¬eKey=a963bd206841796f&sn=https%… 1/1
2/8/23, 1:00 PM SQL for Beginners - Part 66 - Using Sub Queries for retrieving the records from multiple tables
1. Practical Demonstration
1. Select city,(Select country from country where country.country_id=city.country_id)
country from City;
1. Will get the records
2. Select country,(Select city from city where country.country_id=city.country_id) city
from Country;
1. Will get an error
2. Sub Query resulting in multiple records, will give an error
Regards,
Arun Motoori
https://www.evernote.com/shard/s433/client/snv?noteGuid=a8b927af-4ab0-4119-a293-e089a9b89e45¬eKey=6c7236d0f637e966&sn=https%… 1/1
2/8/23, 1:00 PM SQL for Beginners - Part 67 - Using Multiple Sub Queries in a single SQL statement
1. Practical Demonstration
1. List out the films having the length less than the maximum length and having the
rental duration equal to the minimum rental duration
1. Finding the maximum length of the films
1. select max(length) from film;
2. Finding the minimum rental duration of the films
1. select min(rental_duration) from film;
3. Now list out the films having the length less than the maximum length
and having the rental duration equal to the minimum rental duration
1. select title,length,rental_duration from film
2. where length < (select max(length) from film)
3. and rental_duration = (select min(rental_duration) from film);
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=38e5c7cf-681b-4330-8af0-120da2b4a7bf¬eKey=5616ce410f381f79&sn=https%3A… 1/1
2/8/23, 1:01 PM SQL for Beginners - Part 68 - Integrity Constraints
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=f8cb8ab6-46db-49ac-809d-061e592fe73e¬eKey=3c2a2f46b37d62a5&sn=https%3… 1/1
2/8/23, 1:02 PM SQL for Beginners - Part 69 - Not Null (Integrity Constraint)
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=95a4ea39-211b-4fc9-a15a-8c8e4bdfd0bd¬eKey=d71af1100f8471de&sn=https%3… 1/1
2/8/23, 1:02 PM SQL for Beginners - Part 70 - Unique (Integrity Constraint)
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=2849f239-e4c4-4c79-ac17-a733d87c6c56¬eKey=457e66fb40aa654f&sn=https%3… 1/1
2/8/23, 1:02 PM SQL for Beginners - Part 71 - Primary Key (Integrity Constraint)
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=44af19bb-de1e-4255-baee-9531b32dc1bc¬eKey=b201fc764e8ac893&sn=https%3… 1/1
2/8/23, 1:03 PM SQL for Beginners - Part 72 - Foreign Key (Integrity Constraint)
Regards,
https://www.evernote.com/shard/s433/client/snv?noteGuid=a2d0c49c-b2b6-4503-a246-3e318be658c3¬eKey=7b6318eabdda714e&sn=https… 1/1
2/8/23, 1:03 PM SQL for Beginners - Part 73 - Check (Integrity Constraint)
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=9ecb10c8-9650-46d9-a52e-54369566d426¬eKey=dd5469d6fd5dc237&sn=https%… 1/1
2/8/23, 1:03 PM SQL for Beginners - Part 74 - Default (Integrity Constraint)
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=f5e5476d-3289-472e-af71-03ca8a0d3b4e¬eKey=fdb3a6d65bcbc6f8&sn=https%3… 1/1
2/8/23, 1:04 PM SQL for Beginners - Part 75 - auto_increment
1. auto_increment will increment the values of the Table columns by one, if we are not inserting
any data
2. Practical Demonstration
1. create table empone(id int primary key auto_increment,name varchar(15));
1. insert into empone values(5,'Arun');
2. insert into empone(name) values('Varun');
3. insert into empone values(9,'Tharun');
4. insert into empone(name) values('Dinesh');
2. create table emptwo(id int primary key auto_increment,name varchar(15));
1. insert into empone(name) values('Arun');
2. insert into empone(name) values('Varun');
3. create table emptwo(id int primary key auto_increment,name varchar(15))
auto_increment=100;
1. insert into empone(name) values('Arun');
2. insert into empone(name) values('Varun');
Regards,
Arun Motoori
https://www.evernote.com/shard/s433/client/snv?noteGuid=2286827e-d965-4218-a046-cdd25bb873ea¬eKey=6fdca7aa3ff0be3b&sn=https%3… 1/1
2/8/23, 1:05 PM SQL for Beginners - Part 76 - Insert Into
1. Insert Into Statement is used for copying the records from a table into another table having
same column names and data types
2. Practical Demonstration
1. insert into newcity Select * from city;
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=06490d9b-2dc9-4d46-9a9f-8c69c9b2691b¬eKey=2c9d13f9dad34131&sn=https%3… 1/1
2/8/23, 1:05 PM SQL for Beginners - Part 77 - AS Keyword
1. AS Keyword is used to create a new table with the records of an existing table
2. Practical Demonstration
1. Create Table NewPlace AS Select * from Place;
2. Create Table PlaceTwo AS Select name,district from Place;
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=a5911f45-b93b-472d-8e99-101abc77f030¬eKey=216f9287688b4e14&sn=https%3… 1/1
2/8/23, 1:05 PM SQL for Beginners - Part 78 - IfNull() function
1. IfNull() function is used to provide an alternate value when the column value is null
2. Practical Demonstration
1. create table empone(id int,salary int);
2. Select (ifnull(salary,0)+100000) newsalary from empone;
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=5a6f1405-864d-4fff-84dc-e93fa6e979b3¬eKey=a0c078443eb7eee0&sn=https%3A… 1/1
2/8/23, 1:06 PM SQL for Beginners - Part 79 - Case, When,Then and End Keywords
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=531bbef6-c0f2-4f3f-bdc5-04c412f1c513¬eKey=8e06430e3b4dcb32&sn=https%3A… 1/1
2/8/23, 1:07 PM SQL for Beginners - Part 80 - Delimiter
1. Default Delimiter is ;
2. We can change the delimiter to other symbol
3. Practical Demonstration
1. Select * from city;
2. Delimiter //
3. Select * from city//
4. Different symbols can be used instead of //
5. Delimiters are generally used with Stored Procedures
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=5ef485db-e138-4ce1-9fea-bacec248fd43¬eKey=613b1547cede6fcd&sn=https%3… 1/1
2/8/23, 1:07 PM SQL for Beginners - Part 81 - Delimiter usage in Stored Procedures
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=e5c43652-aaca-4f35-bb43-2c88064bc0b1¬eKey=b49ee4d755989335&sn=https%… 1/1
2/8/23, 1:07 PM SQL for Beginners - Part 82 - Views
1. The main purpose of views is to create different varieties of the same table or tables (Virtual
Tables)
2. We can create Views by customizing the same table columns or by selecting the columns
from multiple tables
3. Hide the Database implementation of the actual tables and show the desired virtual views to
the Users
4. Practical Demonstration
1. create table empone(id int,name varchar(15),country varchar(15));
2. insert into empone values (1,'Arun','India');
3. insert into empone values (2,'Varun','UK');
4. insert into empone values (3,'Tharun','Spain');
5. insert into empone values (4,'Dinesh','New Zealand);
6. select * from empone;
7. create table emptwo(id int,experience int);
8. insert into emptwo values(1,12);
9. insert into emptwo values(2,7);
10. select * from emptwo;
11. create view emponeviewa as Select * from empone;
12. create view emponeviewb as Select id,name from empone;
13. create view emponeviewc as Select id,country from empone;
14. create view emponeviewd as Select country,name,id from empone;
15. create view empviewb as Select empone.id,empone.name,emptwo.experience from
empone,emptwo where empone.id=emptwo.id;
5. Performing operators on the Views will effect the original tables and vice versa
https://www.evernote.com/shard/s433/client/snv?noteGuid=a544849f-5b78-43dd-8818-09fbb7958757¬eKey=e2e299625c4edd99&sn=https%… 1/1
2/8/23, 1:07 PM SQL for Beginners - Part 83 - Indexes
1. Indexes when implemented for a table, will increase the performance of the Application by
retrieving the records at faster speed
2. Indexes are like Table of Contents or Index in a Book, which are provided for faster access of
the required topics
3. Indexes should be implemented for retrieval operations
1. Insertions and Updates will slow down if you create indexes
2. Select operations need indexes for speeder retrieval
4. Practical Demonstration
1. use qafox;
2. create table empone(id int,name varchar(15),experience int,country varchar(15));
3. insert into empone values(1,'Arun',12,'India');
4. insert into empone values(2,'Varun',7,'USA');
5. insert into empone values(3,'Tharun',9,'UK');
6. Select * from empone;
7. Select * from empone where country='USA';
8. show indexes from empone;
9. create index empcountry
10. on empone(country);
11. show indexes from empone;
12. drop index empcountry on empone;
13. create table emptwo(id int primary key,name varchar(15));
1. primary index will be automatically created
2. show indexes from emptwo;
14. create table empthree(id int unique,name varchar(15));
1. id index will be automatically created
2. show indexes from empthree;
Regards,
Arun Motoori
https://www.evernote.com/shard/s433/client/snv?noteGuid=49c5af0e-205c-47ca-be7b-04c3a210d336¬eKey=cce80e72375284c3&sn=https%… 1/1
2/8/23, 1:08 PM SQL for Beginners - Part 84 - JDBC (Conneting to MySQL Database from Java Programs)
https://www.evernote.com/shard/s433/client/snv?noteGuid=f94d3f21-708b-4a5a-b778-6237fd0599a2¬eKey=cf62dbf4e2f3c0af&sn=https%3A… 2/2
2/8/23, 1:09 PM SQL for Beginners - Part 85 - ODBC
1. MySQL Workbench Client internally uses JDBC driver for connecting to the Databases in
MySQL Server
2. SQL ODBC Query Client Tool requires ODBC driver for connecting to the Database in MySQL
Server
3. Downloading and Installing MySQL ODBC Driver
1. Windows Search ODBC and select 64bit
4. Creating DataSource Name
5. Downloading SQL ODBC Query Tool
6. JDBC and ODBC are the popular drivers for connecting to the MySQL DB
Regards,
Arun Motoori
https://www.evernote.com/shard/s433/client/snv?noteGuid=6df4918b-9a71-40c1-8c30-da0e905a72c0¬eKey=3195add564df4829&sn=https%… 1/1
2/8/23, 1:09 PM SQL for Beginners - Part 86 - MySQL Shell Command Line Tool
1. MySQL Shell Command Line Tool for connecting to the MySQL Server
2. Google Search for 'MySQL Shell Commands'
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=8bf28e5d-6127-490c-87b9-2ce7c0a307fe¬eKey=3c914bd7b7836f72&sn=https%3… 1/1
2/8/23, 1:09 PM SQL for Beginners - Part 87 - MySQL Command Line Client
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=1afbaee8-cde1-4525-b4b4-537a1e4dc37d¬eKey=13c859cef5f96524&sn=https%3… 1/1
2/8/23, 1:10 PM SQL for Beginners - Part 88 - Using default Windows Command Prompt for connecting to MySQL Server
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=081095da-77e5-4d1b-9d43-6e288064a4c9¬eKey=487061aa84271787&sn=https… 1/1
2/8/23, 1:11 PM SQL for Beginners - Part 89 - Types of SQL Statements
1. DQL
2. DML
3. DDL
4. TCL
5. DCL
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=e75cca20-baa8-4aab-8814-14ba36d407e2¬eKey=2e9c13677eaef55e&sn=https%… 1/1
2/8/23, 1:11 PM SQL for Beginners - Part 90 - Grant and Revoke SQL Statements
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=b7f317ce-bb39-4acc-9b40-c5f35a321c4b¬eKey=46a9d3aac0ef48c2&sn=https%3… 1/1
2/8/23, 1:11 PM SQL for Beginners - Part 91 - Temporary Tables
1. Practical Demonstration
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=b978b859-8ad5-4aa4-985e-3e1eb7922d47¬eKey=8d77094996e5e840&sn=https… 1/1
2/8/23, 1:12 PM SQL for Beginners - Part 92 - Show Columns,Show Indexes,Show Privileges and Show Grants Statements
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=fc6a3c29-71f1-4dc6-99d1-8fc2bbf95d66¬eKey=8509ca7df6d78429&sn=https%3A… 1/1
2/8/23, 1:14 PM SQL for Beginners - Part 93 - Inserting Null
1. Practical Demonstration
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=8e503b17-b0b3-4e09-985e-527283aa0342¬eKey=6faf0940e56c2913&sn=https%… 1/1
2/8/23, 1:14 PM SQL for Beginners - Part 94 - Using trim() for trimming the corner characters of the specified Table values
1. Practical Demonstration
1. use qafox;
2. Select trim('a' from 'arun');
3. Select trim('a' from 'rana');
4. Select trim('a' from 'aruna');
5. create table empone(name varchar(15));
6. insert into empone values('arun');
7. insert into empone values('naresh');
8. insert into empone values('varun');
9. insert into empone values('tharun');
10. insert into emptwo values('nandan');
11. Select * from emptwo;
12. Select trim('n' from name) from emptwo;
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=e7841d6a-baa1-4b9f-a561-8f73fcf5014c¬eKey=fa9ce73980e048a2&sn=https%3A… 1/1
2/8/23, 1:14 PM SQL for Beginners - Part 95 - Using wild-cards as normal characters
1. Practical Demonstration
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=3afba9c4-8d42-46ab-8f24-d37d72eb3ba8¬eKey=5701b5d8b9f70bd8&sn=https%3… 1/1
2/8/23, 1:15 PM SQL for Beginners - Part 96 - Database Objects
1. Terminology
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=78f5b439-14fd-451e-a5aa-e65215e1c8ec¬eKey=43d8d0fae96c246b&sn=https%3… 1/1
2/8/23, 1:15 PM SQL for Beginners - Part 97 - Creating Linux Virtual Machine
1. Practical Demonstration
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=5fed2ce8-5190-4d54-9642-e59f42ca573a¬eKey=bea2f7ebcd089337&sn=https%3… 1/1
2/8/23, 1:15 PM SQL for Beginners - Part 98 - Installing MySQL in Linux Machine
1. Practical Demonstration
1. sudo apt-get update
2. sudo apt-get install mysql-server
3. sudo mysql_secure_installation
4. sudo service mysql status
5. sudo service mysql stop
6. sudo service mysql start
7. sudo mysql -u root -p
8. Run SQL queries here
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=e9742e41-46db-4c1e-859a-84cc528574e8¬eKey=9f108b0e642609a0&sn=https%… 1/1
2/8/23, 1:15 PM SQL for Beginners - Part 99 - Using Putty for Connecting to a Remote Machine having MySQL and performing SQL operations
1. Practical Demonstration
1. sudo apt install ssh
2. Set to Host only adapter
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=843d51ed-469d-41b6-a053-c6ee052f9d34¬eKey=e6a78c20d5756511&sn=https%… 1/1
2/8/23, 1:16 PM SQL for Beginners - Part 100 - Oracle Database, SQL Plus, SQL Developer and Executing SQL Queries
1. Practical Demonstration
1. Download and Install Oracle
Download Part 1 and Part 2 of the Oracle 11g
2. SQL Plus
3. SQL Developer
Connecting to Oracle DB
4. Executing SQL Queries
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=3056bb88-9940-43f4-b85e-25a4cfd6f35c¬eKey=b7cc1333b607a129&sn=https%3… 1/1
2/8/23, 1:18 PM SQL for Beginners - Part 101 - Oracle SQL Queries
1. Practical Demonstration
1. Retrieving Records:
1. Select * from Countries;
2. Select Country_Name from Countries;
3. Select Country_ID,Country_Name from Countries;
2. Describe
1. describe countries;
3. Where Clause
1. Select * from Countries where Region_Id=2;
4. Order By clause
1. Select * from Countries Order by Country_Name ASC;
2. Select * from Countries Order by Country_Name DESC;
3. Select * from Countries Order by Country_Name;
5. Arithmetic Operators
1. Select Salary,Salary+10000 from Employees;
2. Select Salary,Salary-10000 from Employees;
3. Select Salary,Salary*10 from Employees;
4. Select Salary,Salary/10 from Employees;
6. Relational Operators
1. Select * from Countries where Region_Id=2;
2. Select * from Countries where Region_Id<2;
3. Select * from Countries where Region_Id>2;
4. Select * from Countries where Region_Id<=2;
5. Select * from Countries where Region_Id>=2;
6. Select * from Countries where Region_Id<>2;
7. Logical Operators (and, or, not)
1. Select * from Countries where Region_id=2 and Country_Name<>'Canada';
2. Select * from Countries where Country_name='Canada' or Region_id=3;
3. Select * from Countries where Not region_id=2;
8. Between Operator
1. Select * from Employees where employee_id between 105 and 109;
2. Select * from Employees where employee_id not between 105 and 109;
3. Select * from Employees where first_name between 'Diana' and 'John' order by
first_name ASC;
9. In Operator:
https://www.evernote.com/shard/s433/client/snv?noteGuid=25237a43-a73b-425c-8d64-0f36a15e0614¬eKey=6f48ee6021d4ee59&sn=https%… 1/2
2/8/23, 1:18 PM SQL for Beginners - Part 101 - Oracle SQL Queries
Regards,
Arun Motoori
https://www.evernote.com/shard/s433/client/snv?noteGuid=25237a43-a73b-425c-8d64-0f36a15e0614¬eKey=6f48ee6021d4ee59&sn=https%… 2/2
2/8/23, 1:18 PM SQL for Beginners - Part 102 - Oracle SQL Built-in functions
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=c49a5fd9-18ab-4cfe-acfa-22ffc0cb4e0f¬eKey=2936df44d608f47f&sn=https%3A%… 2/2
2/8/23, 1:18 PM SQL for Beginners - Part 103 - Oracle SQL Queries (Part 2)
1. Practical Demonstration
1. Creating the Table:
1. create table empone(id number(5),name varchar(15));
2. Select * from empone;
2. Inserting the Records into the Table
1. insert into empone values(1,'Arun');
2. insert into empone values(2,'Varun');
3. insert into empone values(3,'Tharun');
4. Select * from empone;
5. insert into empone values(4);
1. Error
6. insert into empone(id) values(4);
7. insert into empone values(5,null);
8. Select * from empone;
9. Select * from empone where name Is Null;
10. Select * from empone where name Is Not Null;
3. Update the Records
1. update empone set name='Kiran' where id=4;
4. Rename the table
1. rename empone to empA;
2. Select * from empone;
3. Select * from empA;
5. Delete the records from the Table
1. delete from empA where id=3;
2. Select * from empA;
3. delete from empA;
4. Select * from empA;
6. Delete the Table itself
1. drop table empA;
7. Data types
1. char
1. create table emptwo(letter char);
2. insert into emptwo values('a');
2. number
1. create table empthree(id number);
https://www.evernote.com/shard/s433/client/snv?noteGuid=557d12bd-ecdc-4166-a6c5-40f25e56fc47¬eKey=50f9d455409b8abb&sn=https%3… 1/2
2/8/23, 1:18 PM SQL for Beginners - Part 103 - Oracle SQL Queries (Part 2)
Regards,
https://www.evernote.com/shard/s433/client/snv?noteGuid=557d12bd-ecdc-4166-a6c5-40f25e56fc47¬eKey=50f9d455409b8abb&sn=https%3… 2/2
2/8/23, 1:18 PM SQL for Beginners - Part 104 - Oracle SQL Queries (Part 3)
1. Practical Demonstration
1. Alter Statement (add, modify, rename column and drop column)
1. create table emp1(id number,name varchar(15));
2. Select * from emp1;
3. alter table emp1 add country varchar(15);
4. Select * from emp1;
5. describe emp1;
6. alter table emp1 modify name varchar(20);
7. describe emp1;
8. alter table emp1 rename column country to location;
9. describe emp1;
10. alter table emp1 drop column location;
11. describe emp1;
2. Single Line and Multi Line Comments
1. -- Create a new table with emp1 name
2. create table emp1(id number,name varchar(15));
3. Select * from emp1;
4. /* Alter the table by doing the below
5. add a new column at the end of the existing columns in the table
6. modify the data type or size of the data type for a particular column
7. rename the name of the column to a different name
8. delete the column */
9. alter table emp1 add city varchar(15);
10. Select * from emp1;
11. describe emp1;
12. alter table emp1 modify name varchar(20);
13. describe emp1;
14. alter table emp1 rename column country to location;
15. describe emp1;
16. alter table emp1 drop column location;
17 describe emp1;
https://www.evernote.com/shard/s433/client/snv?noteGuid=fbfb6c27-9ba4-48d4-9fc3-2ac6c8f87af1¬eKey=a0c9a9dad66fdec6&sn=https%3A… 1/2
2/8/23, 1:18 PM SQL for Beginners - Part 104 - Oracle SQL Queries (Part 3)
17. describe emp1;
3. Group By Clause
Terms of Service Privacy Policy Report SpamSave Copy to Evernote
1. Select * from Countries;
2. Select Count(*) from Countries;
3. Select Count(*) from Countries where Group By region_id;
4. Select region_id, count(*) from Countries where Group By region_id;
4. Having Clause
1. Select region_id,count(*) from Countries group by region_id having count(*)>5;
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=fbfb6c27-9ba4-48d4-9fc3-2ac6c8f87af1¬eKey=a0c9a9dad66fdec6&sn=https%3A… 2/2
2/8/23, 1:19 PM SQL for Beginners - Part 105 - Oracle SQL Queries (Part 4)
1. Practical Demonstration
1. Set Operators
1. We can retrieve the data from different tables at a time using the Set Operators
2. Union (All eliminating duplicates)
1. create table empX(id number);
2. insert into empX values(1);
3. insert into empX values(3);
4. insert into empX values(5);
5. Select * from empX;
6. create table empY(id number);
7. insert into empY values(2);
8. insert into empY values(3);
9. insert into empY values(4);
10. Select * from empY;
11. Select * from empX union Select * from empY;
3. Union All (All and won't eliminate duplicates)
1. Select * from empX union all Select * from empY;
4. Intersect (Common)
1. Select * from empX intersect Select * from empY;
5. Minus (Only the table records which are not there in other table
1. Select * from empX minus Select * from empY;
2. Tables and Aliases
1. Select one.id,one.name,two.country
2. from empdetailsone one,empdetailstwo two
3. where one.id=two.id;
3. Joins
1. The purpose of Joins is to Join two tables for retrieving the records from two
tables
2. create table empxone(id number,firstname varchar(15));
3. insert into empxone values(1,'Arun');
4. insert into empxone values(2,'Varun');
5. insert into empxone values(4,'Tharun');
6. Select * from empxone;
7. create table empxtwo(id number,lastname varchar(15));
8. insert into empxtwo values(1,'Motoori');
https://www.evernote.com/shard/s433/client/snv?noteGuid=30cf2f96-8cd4-4db6-b3bd-b2da3235a97b¬eKey=79d8b80e712b198e&sn=https%… 1/2
2/8/23, 1:19 PM SQL for Beginners - Part 105 - Oracle SQL Queries (Part 4)
8. se t to e p t o a ues( , otoo );
9. insert into empxtwo values(4,'Kumar');
Terms of Service Privacy Policy Report SpamSave Copy to Evernote
10. insert into empxtwo values(5,'Rathod');
11. Select * from empxtwo;
12. Inner Join (Common records)
1. Select * from empxone
2. inner join empxtwo
3. on empxone.id=empxtwo.id;
13. left outer Join (Records in left table will be given importance and the right table
records will be adjusted)
1. Select * from empxone
2. left outer join empxtwo
3. on empxone.id=empxtwo.id;
14. right outer join
1. Select * from empxone
2. right outer join empxtwo
3. on empxone.id=empxtwo.id;
15. full outer join (Both the tables are given importance while joining)
1. Select * from empxone
2. full outer join empxtwo
3. on empxone.id=empxtwo.id;
16. Self Join (Table joining with itself)
1. create table empxthree(id number,firstname varchar(15),lastname
varchar(15),depid number);
2. Select *
3. from empxthree o,empxthree t
4. where o.id=t.depid;
https://www.evernote.com/shard/s433/client/snv?noteGuid=30cf2f96-8cd4-4db6-b3bd-b2da3235a97b¬eKey=79d8b80e712b198e&sn=https%… 2/2
2/8/23, 1:19 PM SQL for Beginners - Part 106 - Oracle SQL Queries (Part 5)
1. Sub Query
1. Sub Query is a query inside another query
2. Outer Query
3. Inner Query (Sub Query)
4. Practical Demonstrations
1. Retrieve all the employees, who are from the same department of Bruce
1. Select department_id from Employees where first_name='Bruce';
2. Select * from Employees where department_id = (Select department_id
from Employees where first_name='Bruce');
5. Types of Sub Queries
1. Single Row Sub Query
2. Multi Row Sub Query
6. Multi-Row Sub Query and different Operators
1. We have to use in,any,all and exits operators
2. In Operator
1. Select * from employees where first_name='Steven';
2. Select department_id from employees where first_name='Steven';
3. Select * from employees where department_id = (Select department_id
from employees where first_name='Steven');
1. Error
4. Select * from employees where department_id In (Select department_id
from employees where first_name='Steven');
3. Any Operator
1. Select Salary from employees where department_id=60;
2. Select * from employees where Salary < (Select Salary from employees
where department_id=60);
1. Error
3. Select * from employees where Salary < any (Select Salary from
employees where department_id=60);
4. All Operator
1. Select * from employees where Salary < all (Select Salary from
employees where department_id=60);
5. Exists Operator
1. Select * from employees where exists (Select * from employees where
department_id=60);
https://www.evernote.com/shard/s433/client/snv?noteGuid=5a0447d3-6307-4905-9003-3939c02b6559¬eKey=03591da7f30db9f7&sn=https%… 1/2
2/8/23, 1:19 PM SQL for Beginners - Part 106 - Oracle SQL Queries (Part 5)
2. Select * from employees where exists (Select * from employees where
department_id=112);
Terms of Service Privacy Policy Report Spam Save Copy to Evernote
2. Integrity Constraints
1. Conditions we can apply on the Table Column Data
2. Not Null
1. Create table QAFoxOne(id number not null,name varchar(15));
2. insert into qafoxone values(1,'Arun');
3. insert into qafoxone(name) values('Varun');
4. insert into qafoxone values(null,'Tharun');
3. Unique
1. create table QAFoxTwo(id number unique,name varchar(15));
2. insert into qafoxtwo values(1,'Arun');
3. insert into qafoxtwo values(1,'Varun');
4. Primary Key
1. create table qafoxthree(id number primary key,name varchar(15));
2. insert into qafoxthree values(1,'Arun');
3. insert into qafoxthree(name) values('Varun');
4. insert into qafoxthree values(null,'Tharun');
5. insert into qafoxthree values(1,'Kiran');
5. Foreign Key
1. create table empp(id number primary key,name varchar(15));
2. insert into empp values(1,'Arun');
3. insert into empp values(2,'Varun');
4. insert into empp values(3,'Tharun');
5. Select * from empp;
6. create table empsal(id number,salary number,constraint empsal_id_rel foreign
key(id) references empp(id));
7. insert into empsal values(1,1400000);
8. insert into empsal values(5,700000);
1. Error
9. insert into empsal values(2,900000);
10. insert into empsal values(3,1100000);
11. Select * from empsal;
12. delete from empp where id=2;
1. Error
13. delete from empsal where id=2;
14. delete from empp where id=2;
6. Check
1. create table qafoxfour(id number,name varchar(15),country varchar(15)
check(country = 'USA'));
2. insert into qafoxfour values(1,'Arun','India');
i i f f l
https://www.evernote.com/shard/s433/client/snv?noteGuid=5a0447d3-6307-4905-9003-3939c02b6559¬eKey=03591da7f30db9f7&sn=https%… 2/2
2/8/23, 1:19 PM SQL for Beginners - Part 107 - DBeaver Universal DB Client Tool
1. Practical Demonstration
1. Installing DBeaver Community Edition
2. Configuring it and using it
Regards,
Arun Motoori
QAFox.com
https://www.evernote.com/shard/s433/client/snv?noteGuid=9dd8691c-efe9-4eb1-a422-1022279fef18¬eKey=0ecb301d41e30459&sn=https%3… 1/1
2/8/23, 1:19 PM SQL for Beginners - Part 108 - XAMPP for Practicing SQL
1. Practical Demonstration
1. Installing XAMPP
2. Practicing SQL
1. Install Database in our local machine and start it
Download XAMPP from here and install it
Launch XAMPP and Start MySQL Relational Database Software which
comes by default with XAMPP
2. Open command prompt from C:/XAMPP/mysql/bin folder, connect to MySQL
database system and trigger different SQL statements given below:
Launch the command prompt from C:/XAMPP/mysql/bin folder
Provide a password to the Database System using -
mysqladmin.exe -u root password root
Now connect to Database using - mysql -u root -p
When prompted for password type root and press Enter
View the default databases inside the MySQL using - show databases;
Create a new database in MySQL using - create database qafox;
Confirm its creation using show databases;
Pick the newly created database using - use qafox;
View the tables inside the qafox database using - show tables;
Create a new table using - create table Employee(Name
VARCHAR(50), Location VARCHAR(50), Experience INTEGER);
Confirm its creation using show tables;
View the records inside the table using - select * from Employee;
Observe that you will see no records
Insert the new records into the table using:
Insert into Employee values('Venkat','Hyderabad',10);
Insert into Employee values('Gopal','Bangalore',8);
Insert into Employee values('Niharika','Pune',3);
Confirm new records insertion using select * from Employee;
Regards,
https://www.evernote.com/shard/s433/client/snv?noteGuid=a9753b9a-ecd5-4212-ab4a-3d7697d9fd7e¬eKey=4dbd1d59555ac48f&sn=https%… 1/1
2/8/23, 1:20 PM SQL for Beginners - Part 109 - Savepoint
By,
Arun Motoori;
https://www.evernote.com/shard/s433/client/snv?noteGuid=4fd275fb-d4ee-488c-8ee9-f9cc9dbe41b7¬eKey=c10ca07df17f8db3&sn=https%3A… 1/1
2/8/23, 1:20 PM SQL for Beginners - Part 110 - Uninstalling MySQL Server completely from Windows Machine
By,
Arun Motoori
https://www.evernote.com/shard/s433/client/snv?noteGuid=22107334-f9dc-4205-9df5-dd994e80ce69¬eKey=2c086b3f59331b1b&sn=https%3… 1/1