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

Using SQL in SELECT Queries (Rules) Use It After The Equal, Greater Than, Less Than Signs (, , )

The document provides examples and rules for using SQL in SELECT queries. It discusses using SELECT queries with operators like =, >, <, IN, and LIKE. It also provides examples of using subqueries in the SELECT list, FROM clause, and in DELETE statements. The document emphasizes that NULL values require IS NULL, IN replaces multiple ORs, and GROUP BY is needed for non-aggregate columns in the SELECT list. It also distinguishes between HAVING and WHERE.

Uploaded by

Eugen Sunic
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)
45 views

Using SQL in SELECT Queries (Rules) Use It After The Equal, Greater Than, Less Than Signs (, , )

The document provides examples and rules for using SQL in SELECT queries. It discusses using SELECT queries with operators like =, >, <, IN, and LIKE. It also provides examples of using subqueries in the SELECT list, FROM clause, and in DELETE statements. The document emphasizes that NULL values require IS NULL, IN replaces multiple ORs, and GROUP BY is needed for non-aggregate columns in the SELECT list. It also distinguishes between HAVING and WHERE.

Uploaded by

Eugen Sunic
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
You are on page 1/ 2

Using SQL in SELECT queries (rules)

Use it after the equal, greater than, less than signs (=,>,<):
SELECT titles, price
FROM Books, Orders
WHERE price =
(SELECT MIN(price)
FROM Orders) AND (Books.ID=Orders.ID);

Use it after keyword IN:


SELECT SUM (Sales) FROM Store_Information
WHERE Store_Name IN
(SELECT Store_Name FROM Geography
WHERE Region_Name = 'West');

Use it as a column (1):


SELECT column1 = (SELECT column-name FROM table-name WHERE condition),
column-names
FROM table-name
WHERE condition

Use it as a column (2):


SELECT Ord.OrderID, Ord.OrderDate,
(SELECT MAX(OrdDet.UnitPrice)
FROM Northwind.dbo.[Order Details] AS OrdDet
WHERE Ord.OrderID = OrdDet.OrderID) AS MaxUnitPrice
FROM Northwind.dbo.Orders AS Ord

Use it after from:


SELECT COUNT (*) FROM
( SELECT IdCover FROM x90..dimCover group by idCover having count(*) > 1) AS a

Using SQL queries in DELETE


MUST KNOW
1. We can not use '=' sign for to check fo null value because null is a special
value. We must use IS NULL to check if the value is null.
2. IN operator replaces multiple OR's
3. The LIKE operator is used in a WHERE clause to search for a specified pattern
in a column.
Example: SELECT * FROM Customers
WHERE City LIKE 's%';
You can also use NOT along with it.

4. TRUNCATE TABLE NazivTablice- delete all table rows


5. Svi atributi koji se nalaze u listi za selekciju, a nisu dio agregatnih funkcija,
moraju biti navedeni u GROUP BY dijelu SELECT naredbe
Primjer:

6. Having-refers to GROUP BY , WHERE-filters rows


7. Add the foreign key to the dependent table.

Example: Users don't need PowerUser information.

You can wright things this way:

You might also like