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

Assign1 Ans

The document provides examples of 10 SELECT statements to retrieve data from database tables. The SELECT statements demonstrate basic filtering, sorting, and aggregation of data. Some examples select all columns, while others select specific columns. The statements filter on columns like course number, state, last name, zip code, cost, and prerequisite. They sort results by columns like course number, zip, and last name.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
182 views

Assign1 Ans

The document provides examples of 10 SELECT statements to retrieve data from database tables. The SELECT statements demonstrate basic filtering, sorting, and aggregation of data. Some examples select all columns, while others select specific columns. The statements filter on columns like course number, state, last name, zip code, cost, and prerequisite. They sort results by columns like course number, zip, and last name.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment #1

Simple Queries

1. Write a SELECT statement to list course data sorted by course number. (30 rows)
SELECT *
FROM course
ORDER BY course_no
2. Write a SELECT statement to list zipcodes and their cities in New York State sorted by
zipcode. (123 rows)

SELECT
FROM
WHERE
ORDER

zip, city
zipcode
state = 'NY'
BY zip

3. Write a SELECT statement to list first and last names of all instructors sorted by last name.
(10 rows)

SELECT first_name, last_name


FROM instructor
ORDER BY last_name
4. Write a SELECT statement to list courses that have the course number 20 as a prerequisite.
(5 rows)

SELECT *
FROM course
WHERE prerequisite = 20
5. Write a SELECT statement to list the last and first names in last name order of students that
are currently employed by the firm Electronic Engineers and have last names starting with
"G". (2 rows)

SELECT
FROM
WHERE
AND
ORDER

last_name, first_name, employer


student
employer = 'Electronic Engineers'
last_name LIKE 'G%'
BY last_name

6. Write the same SELECT statement as #5 but include students who are Electronic Engineers
employees with the last name beginning with S or B. (Hint: Use parentheses in the WHERE
clause to isolate the OR logic). (2 rows)

SELECT
FROM
WHERE
AND
ORDER

last_name, first_name, employer


student
employer = 'Electronic Engineers'
(last_name LIKE 'S%' OR last_name LIKE 'B%')
BY last_name

7. Write a SELECT statement to list students that live either in zip code 11433, 11434, or 11435.
(5 rows)

SELECT *
FROM student
WHERE zip IN ('11433', '11434', '11435')
8. Write a SELECT statement to list the courses that cost $1095 or less. (3 rows)

SELECT *
FROM course
WHERE cost <= 1095
9. Write a SELECT statement to list the first and last name of students that do not have the
salutation of "Dr.". (267 rows)

SELECT first_name, last_name


FROM student
WHERE salutation <> 'Dr.'
10. Write a SELECT statement to list courses that do not have a prerequisite. (4 rows)

SELECT course_no, prerequisite


FROM course
WHERE prerequisite IS NULL

You might also like