Aptitude (12) ASP.NET (2) Automata (4) Browser (1) C (5) C# (1) C++ (10) Code (3) CSS (1) Data Structure (1) DATABASE (3) HTML (1) java (43) JSP (1) math (1) MySql (8) other (6) php (3) Servlet (3)

Sunday, 30 December 2012

SQL-Queries



create table Myset
(
name varchar(15),sal int,age int
)
insert into Myset values('e',5,50)
select*from Myset
select*from Myset order by sal desc
select*from Myset order by sal asc
select*from Myset where  sal not in (3,5)
select*from Myset where  sal in (3,5)
select*from Myset where  sal is  not null
select*from Myset where  sal between 2 and 5
select max(sal)from Myset
select min(sal)from Myset
select avg(sal)from Myset
select sum(sal)from Myset
select count(sal)from Myset
select max(sal)from Myset where sal<>(select max(sal) from Myset)
select sal,max(age)from Myset group by sal

select * from Stu_Table
where Stu_Name like '%k%'

SELECT * FROM Stu_Class_10
UNION ALL
SELECT * FROM Stu_Class_12

SELECT * FROM Stu_Class_10
UNION
SELECT * FROM Stu_Class_12

SELECT column_name(s)
FROM table_name1
right JOIN table_name2 
ON table_name1.column_name=table_name2.column_name

CREATE VIEW Stu_View( Stu_id, Stu_Name, Stu_Class)
AS SELECT  Stu_id, Stu_name, Stu_class
FROM Stu_Table

Select * from Stu_View
SELECT Stu_Id, Stu_Name, Stu_Class
FROM Stu_Table
where Stu_Id = 1 AND Stu_name = 'komal'

select * from Stu_Table
where stu_name like 'k%'AND stu_id = 1

select s.stu_id, s.stu_name, s.stu_class
from Stu_Table as s , Stu_Table as l
where s.stu_id = l.stu_id

No comments:

Post a Comment