0% found this document useful (0 votes)
20 views

SQL Queries

It is how to create a database, tables, select, insert, update and delete queries in DBMS. It is simple and easy to understand.

Uploaded by

Sudheer Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

SQL Queries

It is how to create a database, tables, select, insert, update and delete queries in DBMS. It is simple and easy to understand.

Uploaded by

Sudheer Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 6

SELECT * FROM table_name;

SELECT Syntax:
SELECT column_name,column_name
FROM table_name;
ex:
SELECT CustomerName,City FROM Customers;

SELECT DISTINCT Syntax:


SELECT DISTINCT column_name,column_name
FROM table_name;(column may contain many
duplicate values, it doesn't allows duplicate values &
display in assending order)
ex:
SELECT DISTINCT City FROM Customers;

WHERE Syntax:
SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;
ex:

{SELECT * FROM Customers


WHERE Country='Mexico';}

{SELECT * FROM Customers


WHERE Country='Germany'
AND City='Berlin';}

{SELECT * FROM Customers


WHERE City='Berlin'
OR City='Mnchen';}

SELECT * FROM Customers


WHERE Country='Germany'
AND (City='Berlin' OR City='Mnchen');

ORDER BY Syntax:
SELECT column_name,column_name
FROM table_name
ORDER BY column_name,column_name ASC|DESC;

ex:

SELECT * FROM Customers


ORDER BY Country;

SELECT * FROM Customers


ORDER BY Country DESC;
SELECT * FROM Customers
ORDER BY Country,CustomerName;

INSERT INTO Syntax:


INSERT INTO table_name
VALUES (value1,value2,value3,...);

INSERT INTO table_name


(column1,column2,column3,...)
VALUES (value1,value2,value3,...);

ex:
INSERT INTO Customers (CustomerName,
ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal','Tom B. Erichsen','Skagen
21','Stavanger','4006','Norway');

INSERT INTO Customers (CustomerName, City,


Country)
VALUES ('Cardinal', 'Stavanger', 'Norway');

UPDATE Syntax:
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;

ex:
UPDATE Customers
SET ContactName='Alfred Schmidt', City='Hamburg'
WHERE CustomerName='Alfreds Futterkiste';
Update Warning!
we had omitted the WHERE clause:
UPDATE Customers
SET ContactName='Alfred Schmidt', City='Hamburg';
(x) statement

DELETE Syntax:
DELETE FROM table_name

WHERE some_column=some_value;
ex:
DELETE FROM Customers
WHERE CustomerName='Alfreds Futterkiste' AND
ContactName='Maria Anders';
DELETE FROM table_name;
or
DELETE * FROM table_name;

SELECT TOP Clause:


SELECT TOP number|percent column_name(s)
FROM table_name;
ex:
SELECT TOP 2 * FROM Customers;

SELECT TOP 50 PERCENT * FROM Customers;

LIKE Syntax:
SELECT column_name(s)
FROM table_name

WHERE column_name LIKE pattern;


ex:
selects all customers with a City starting with the
letter "s":
SELECT * FROM Customers
WHERE City LIKE 's%';
selects all customers with a City ending with the
letter "s":
SELECT * FROM Customers
WHERE City LIKE '%s';
selects all customers with a Country containing the
pattern "land":
SELECT * FROM Customers
WHERE Country LIKE '%land%';
selects all customers with a Country NOT containing
the pattern "land":
SELECT * FROM Customers
WHERE Country NOT LIKE '%land%';

You might also like