Simple Queries in SQL
Simple Queries in SQL
• INTRODUCTION
1. Literals .
2. Datatypes.
3. Nulls.
4. Comments.
Literals
- Literals, in generals, refers to a fixed data value. This fixed data value
may be of character type or numeric literals. For example, ‘Parag Jain’,
17, and 18 are all literals.
- Numbers that are not enclosed in quotation marks are numeric
literals e.g., 22, 18, 17, 3027, 2021 are all numeric literals.
Comments
- A comment is a text that is not executed ; it is only for
documentation purpose.
SQL Command syntax
- SQL provides a predefined set of commands that are
1. KEYWORDS .
2. STATEMENTS.
3. CLAUSES.
4. ARGUMENTS.
commands in SQL are not case sensitive and all commands are execute
in mysql>
Creation of database
• For making database we have to execute this command :-
Mysql> CREATE DATABASE <database name>;
For example : create database school;
Use of database
• MySQL> use <database name>;
• For ex: use school
Table creation
For making table in database we’ve to execute commands which are as
follows :-
• for ex:
Mysql> alter table student add (class int(2));
DESC Command
• This command is used for viewing structure of the table.
• Mysql> DESC <table name> ;
For example :
Drop command
DELETE
DELETE FROM table_name
WHERE some_column = some_value;
DELETE statements are used to remove rows from a table.
INSERT
INSERT INTO table_name (column_1, column_2, column_3)
VALUES (value_1, 'value_2', value_3);
INSERT statements are used to add a new row to a table.
Handling Nulls
IFNULL
MySQL> SELECT name, birth, IFNULL (death, “alive”)
From pet;
SQL : Manipulation
CREATE TABLE
Statement
The INSERT INTO statement is used to add a new record (row) to a table.
UPDATE table_name
SET column1 = value1, column2 = value2
WHERE some_column = some_value;
Column Constraints
Column constraints are the rules applied to the values of individual columns:
SELECT *
FROM movies
WHERE year BETWEEN 1980 AND 1990;
AND Operators
SELECT model
FROM cars
WHERE color = 'blue'
AND year > 2014;
SQL : Aggregate Functions
AVG()
Aggregate Function
SELECT AVG(salary)
FROM employees
WHERE experience < 5;
MAX()
Aggregate Function
SELECT MAX(amount)
FROM transactions;
MIN()
Aggregate Function
SELECT MIN(amount)
FROM transactions;
THE END.
Presented by – Aryan dev.
Class – 11 commerce.
th