Online Courses
Free Tutorials  Go to Your University  Placement Preparation 
Artificial Intelligence(AI) & Machine Learning(ML) Training in Jaipur
Online Training - Youtube Live Class Link
0 like 0 dislike
60 views
in Artificial Intelligence(AI) & Machine Learning by Goeduhub's Expert (3.1k points)

SQL basic queries explained with examples like SELECT, Distinct, WHERE, Order by and operators etc.  How to Check Null Values in Database ? What is SQL JOINs with example? How many JOINs in SQL? SQL JOINS (Inner, left, right, full) are explained with example.

Goeduhub's Online Courses @Udemy

For Indian Students- INR 570/- || For International Students- $12.99/-

S.No.

Course Name

Apply Coupon

1.

Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence

Apply Coupon

2.

Computer Vision with OpenCV | Deep Learning CNN Projects

Apply Coupon

3.

Complete Machine Learning & Data Science with Python Apply Coupon

4.

Natural Language Processing-NLP with Deep Learning in Python Apply Coupon

5.

Computer Vision OpenCV Python | YOLO| Deep Learning in Colab Apply Coupon

6.

Complete Python Programming from scratch with Projects Apply Coupon

1 Answer

0 like 0 dislike
by Goeduhub's Expert (3.1k points)
edited by
 
Best answer

Some Basic Queries: 

Note: Note that SQL is not case sensitive meaning SELECT and select are the same things in SQL. 

SELECT:  Select keyword or statement is used to select whole data or particular column/ columns from the database. 

Syntax:   Select particular column/ columns from a table 

SELECT column_name1, column_name2, ......
FROM table_name;

Select whole data means selecting the whole table 

SELECT * FROM table_name;

Sometimes we need to select unique data from the table, not whole. For this, we can use the SELECT DISTINCT  statement. SELECT DISTINCT returns only unique values from table.

SELECT DISTINCT column_name FROM table_name;

Operators and WHERE in SQL  

We know how to select data from a database but what if we have to define the position or range of particular data that we want to select.

For example, if we have a salary column in a particular database and we want to select a salary greater than a particular value. 

We know that to do it we have to put conditions for what we want. Let's see how to write a query for this. 

SELECT column_name FROM table_name WHERE put_condition;

Different types of operators can be used to put conditions according to the problems.                                         

  Operators  Description 
                    =Equal to 
                 >, >=
greater than , grater than equal to 
                 <, <=Less than, Less than equal to 
                    !=Not equal 
             BETWEEN Between a certain range 
                       IN Used to match multiple values in one column 
                     AND Will display a record if all conditions are true
                     ORWill display a record if any condition is true 
                     NOT When we don't want condition to be true/ !=

Display sorted records 

In SQL, ORDER BY Keyword is used to display sorted records. You can sort  two columns together. In sorting, the first column name that you mentioned first, will sorted first and then the second one. 

By default  ORDER BY Keyword sort in ascending order but if you want in descending you can use the  DESC keyword.

SELECT * FROM table_name
ORDER BY column_name1, column_name2; 

For Descending 

SELECT * FROM table_name
ORDER BY column_name1, column_name2 DESC;

How to Check Null Values in Database ?  

Sometimes we have missing values or null values in our database. To find out null values we use IS NULL Keyword and for not missing values IS NOT NULL.

SELECT * FROM table_name
WHERE column_name IS NULL;

For Not Missing Values 

 SELECT * FROM table_name

WHERE column_name IS NOT NULL;

Selecting Top Records 

Selecting top records meaning, when we have large data we can write a query that returns a limited number of records (or top records).

SELECT TOP number
FROM table_name
WHERE condition;

Some Mathematical Operations (SUM(), COUNT(), AVG() etc...)

SELECT MIN/MAX(column_name)
FROM table_name
WHERE condition ; ( if  required)

MIN()- Return smallest value of field (column)

MAX()- Return largest value of field (column)

SELECT AVG/COUNT/SUM(column_name)
FROM table_name
WHERE condition ; ( if  required)

AVG()- Return average of column (use for numerical column)

COUNT()- Return number of data in a column (or number of rows in a column)

SUM() - Return sum of field (column)

SQL JOINS (Inner, left, right, full)

SQL join, combine two or more columns based on matching values of records/rows.

INNER JOIN or JOIN- Returns matching records of two or more tables.

SELECT table1.column1,table2.column2....
FROM table1
INNER JOIN table2
ON table1.matching_column = table2.matching_column;

LEFT JOIN- Select all records from left table and matched records from right table.

SELECT table1.column1,table2.column2...
FROM table1
LEFT JOIN table2
ON table1.matching_column = table2.matching_column;

RIGHT JOIN- Select all  records from right table and matched records from left table.

SELECT table1.column1,table2.column2....
FROM table1
RIGHT JOIN table2
ON table1.matching_column = table2.matching_column;

FULL JOIN- Returns all matching records as well as non-matching records from both tables.

SELECT table1.column1,table2.column2....
FROM table1
FULL JOIN table2
ON table1.matching_column = table2.matching_column;

 

matching_column - matching column in both table.

Diagrams: 

joins

SQL interview questions and answers. (part-3)

Our Mentors(For AI-ML)


Sharda Godara Chaudhary

Mrs. Sharda Godara Chaudhary

An alumna of MNIT-Jaipur and ACCENTURE, Pune

NISHA (IIT BHU)

Ms. Nisha

An alumna of IIT-BHU

Related questions

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 
...