You are on page 1of 2

SQL Queries:

1)to check databases


-> show databases;

2)to create a database


->

3)to specify the database to use


-> use database;

4)
->

5)to create table


-> create table table_name(column);

6)to check the description of the table


-> desc table_name;

7)to modify table name


-> alter table old_tablename to new_tablename;

8)to insert records into table


-> insert into table_name(columns) values();

9)to retrive the data from table


-> select * from table_name;

10)to add new columns on table


-> alter table table_name add column_name type,...;

11)update record :using where clause


->update table_name set column_name=value where sid=102;

12) delete a record: using where clause


-> delete from table_name where <condition>;

13)change attribute_name for temporary basis using alisas at the time of display
-> select sid as 'student_id',name as 'student' name' from table_name;

14)distinct is used to return value only distinct(different) values inside table ,


column contains sometimes a column many contain duplicate values
-> select distinct(city) from table_name;
->select count(distinct city) from table_name;
->select count(distinct city) as no_of_cities from table_name;

15)to change column name perrmanently


->alter table table_name rename column old colname to new col name;

16)AND operator
->

17)OR operator
->

18)select details whose id strts from 102 to 104


->select * from table_name where sid between 102 and 104;
19)select those students details whose marks are 75,80,81,82
->select * from table_name where marks in(75,80,81,82);

20)to retrive the data from top


->select * from table_name limit 3; //(top 3)

21)sort record in ascending order


->selct * from table_name order by student name;
->selct * from table_name order by student name desc;
->selct * from table_name order by marks;
->selct * from table_name order by student name desc limit 2;

22)like operator is used in a where clause to search for a specified pattern in


a column.there are two wild cards often used in conjection with th elike operator
i)percentage sign(%)--represents zero ,one or many characters
ii)underscore sign(_)--represents one./single character.
-->select * from table_name where student_name like 'a%';

23)calculate total marks


->select sum(marks) as total_marks from table_name;

24)to count total no of recorddsd


->select count(*) as 'no_of_students' from table_name;

25)to find min and max marks


->select min(*) as 'lowest_marks' from table_name;
->select max(*) as 'highest_marks' from table_name;

You might also like