0% found this document useful (0 votes)
42 views1 page

SQL Queries

The document contains examples of different SQL queries including: selecting data with constraints and sorting, counting and averaging aggregate functions, creating and updating views, displaying internal tables, selecting the top 25 rows, searching with wildcards, and finding the intersection of tables using an inner join.

Uploaded by

Asif Hossain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views1 page

SQL Queries

The document contains examples of different SQL queries including: selecting data with constraints and sorting, counting and averaging aggregate functions, creating and updating views, displaying internal tables, selecting the top 25 rows, searching with wildcards, and finding the intersection of tables using an inner join.

Uploaded by

Asif Hossain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Some queries:

Query for Outputting Data Using a Constraint


SELECT EMP_ID, NAME FROM EMPLOYEE_TBL WHERE EMP_ID = '0000';

Query for Outputting Sorted Data Using ‘Order By’


SELECT EMP_ID, LAST_NAME FROM EMPLOYEE
WHERE CITY = 'Seattle' ORDER BY EMP_ID;

Data Manipulation Using COUNT


Syntax: SELECT COUNT(colname) FROM table name;
SELECT COUNT(CustomerID), Country FROM Customers GROUP BY Country;

Data Manipulation Using AVG


SELECT AVG(Price)FROM Products;

Query for Creating a View


CREATE VIEW Failing_Students AS
SELECT S_NAME, Student_ID
FROM STUDENT
WHERE GPA > 40;

Query for Updating a View


CREATE OR REPLACE VIEW [ Product List] AS
SELECT ProductID, ProductName, Category
FROM Products
WHERE Discontinued = No;

Displaying Internal Tables


SELECT * FROM Sys.Objects WHERE Type='it'

Making a Top 25 with the SELECT TOP Clause


SELECT TOP 25 FROM Customers WHERE Customer_ID<>NULL;

Searching for SQL Tables with Wildcards


SELECT * From Customers WHERE Name LIKE 'Herb%'

Finding the Intersection of Two Tables


SELECT ID FROM Customers INNER
JOIN Orders ON Customers.ID = Orders.ID

You might also like