0% found this document useful (0 votes)
5 views3 pages

SQL Query Examples and Functions Guide

The document contains SQL queries for selecting, joining, updating, inserting, and performing calculations on data from database tables. The queries select columns from tables, join tables, filter on dates, strings, and mathematical conditions, calculate aggregates, and use subqueries.

Uploaded by

Ashok Reddy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

SQL Query Examples and Functions Guide

The document contains SQL queries for selecting, joining, updating, inserting, and performing calculations on data from database tables. The queries select columns from tables, join tables, filter on dates, strings, and mathematical conditions, calculate aggregates, and use subqueries.

Uploaded by

Ashok Reddy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Select querys:

select *from titles where price between 20 and 50

select *from Employees where HireDate>'1990-12-01' and ReportsTo between 4 and 6;

select EmployeeID,HireDate from Employees

join querys:

select pub_id,pub_name as title from publishers where city like 'B%'

select pub_name from titles t,publishers p where t.pub_id=p.pub_id and title='Net Etiquette'

select ytd_sales as sales,title from titles t,publishers p where t.pub_id=p.pub_id and


pub_name='New Moon Books'

select title,pub_name from titles t,publishers p where t.pub_id=p.pub_id and city like 'B%'

select query:

select *from employee where hire_date= '1981-02-13'

update querys:

update employee set lname='Drexler' where emp_id='VPA30890F'

update employee set job_id=14 where fname='pedro'


insert query:

insert into employee(emp_id,fname,minit,lname,job_id,job_lvl,pub_id,hire_date) values


('PMA42629M','karthik','T','gurram',5,209,3245,'1998-05-09')

date query:

select *from employee where hire_date between '1992-01-01' and '1992-03-31'

string functions:

SELECT RIGHT(fname, 3) from employee

Mathematical functions:

SELECT *from employee where job_lvl like '___'

SELECT *from employee where job_lvl like '%0'

SELECT *from employee where mod(job_lvl,2)=1

Date Functions:

SELECT *from employee where job_lvl =200 or job_lvl=300 or job_lvl='175'

select *from employee where hire_date between '1992-09-01' and '1992-12-31'


Group by functions:

select min(job_lvl) from employee

select count(emp_id) from employee

select *from employee where minit='T'

sub query functions:

SELECT title, royalty FROM titles WHERE royalty = (SELECT MAX(royalty) FROM titles);

You might also like