CREATE TABLE:
CREATE table student(
stdroll int,
stdname varchar(20),
department varchar(20),
year int);
INSERT :
INSERT INTO students values(01,'shobi','CSE',4),(02,'Nandhini','CSE',4),(03,'Sandra','ECE',2),(05,'Hindhu','EEE',1);
output:
SELECT:
SELECT * from students;
output:
1 . SPECIFICATION SELECTION IN THE TABLE :
SELECT stdname,stddept from students;
output:
ALTER THE TABLE:
ALTER table students rename to std;
output:
SELECT DISTINCT
The SELECT DISTINCT statement is used to return only distinct (different) values.
Inside a table, a column often contains many duplicate values and sometimes you only want to list the different (distinct) values.
SELECT distinct stddept from std;
output:
IF doesnot use the distinct means it will return only selected column values only
WHERE CLAUSE:
- The WHERE clause is used to filter records.
SELECT * from std WHERE stddept='CSE';
output:
WHERE and:
- WHERE and is same like the other programming language like if both condition true means its execute , if anyone condition false means it execute 0 rows.
SELECT * from student WHERE stddept='ECE' and year=4;
output:
SELECT * from student WHERE stddept='CSE' and year=4;
output:
WHERE or:
WHERE or is also same like other programming language if anyone condition true means it will execute otherwise its execute 0 rows.
SELECT * from student WHERE stdname='shobi' or stddept='ECE';
ouput:
SELECT * from student WHERE stdname='divya' or stddept='AGRI';
output:
AS:
SQL aliases are used to give a table, or a column in a table, a temporary name.
SELECT stddept as department from student;
output:
*WHERE NOT : *
SELECT * from student WHERE stddept <> 'ECE';
or
SELECT * from student WHERE != stddept='ECE';
or
SELECT * from student WHERE not stddept='ECE';
output:
> GREATER THAN:
SELECT * from student WHERE year>2;
output:
< LESS THAN:
SELECT * from student WHERE year>4;
output:
BETWEEN:
The BETWEEN operator is used to specify the within the range of the given value.
SELECT * from student WHERE stdname BETWEEN 'hindhu' AND ' shobi';
output:
IN :
The IN operator is used to specify the list of possible value .
SELECT * from student WHERE stddept in ('CSE','ECE');
output:
ORDER BY:
Order by is used to sort the values in the database usually order by give the values in ascending order. we can also change it in descending order.
SELECT * from student ORDERBY stdname;
output:
If you want the student name in descending order means you have to give the desc ;
SELECT * from student ORDE BY stdname desc;
output:
LIMIT:
Limit is used to get the limited amount of data like if we want first 5 data means we can give limit 5 then it display the first 5 data.
SELECT stdrollno, stdname from student limit 3;
output:
In Limit we can use the order by keyword
SELECT * from student ORDER BY stddept limit 3;
output:
LIKE :
Like operator is used to get the values in database based on starting letter, ending letter and also inbetween letter
if you want starting letter means 's%';
if you want ending letter means '%s';
if you want inbetween letter means '%a%';
SELECT stdname from student WHERE stdname LIKE '%i';
output:
SELECT stdname from student WHERE stdname LIKE 'h%';
output:
SELECT stdname from stduent where stdname like '%a%';
output:






















Top comments (0)