SQL 2 Flashcards

1
Q

What do we use the ; (semi colon) for in SQL?

A

The ; (Semi colon) is used to terminate a statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What statement would return all records from a Table called ‘Emp’ where the surname is Jones. We Want all columns returned.

A

SELECT *
FROM Emp
WHERE surname = ‘Jones’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

We want to return surname Jones and JobTitle is Musician. What statement will do this?

Table name is Emp
All Columns to be Returned

A

SELECT *
FROM Emp
WHERE surname = ‘Jones’
AND JobTitle = ‘Musician’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What order would these words appear in an SQL statement? WHERE, FROM, AND SELECT

A

SELECT
FROM
WHERE
AND

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

From a table called EMP we want to return only the firstname, secondname, Sal and dept columns where surname is Jones and Sal is more than 60000

A

SELECT Firstname, secondname, sal, dept
FROM EMP
WHERE secondname = ‘Jones’
AND Sal > 60000;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

STRINGS are wrapped in…,,,,,,?

A

Quotation Marks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Write a query that will return all employees that have a commission (Comm) greater than their Salary (Sal).

Tablename is EMP
All Columns to be returned

A

SELECT *
FROM Emp
WHERE comm > sal;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Write a query that returns all employees (Job) that are NOT managers, have a salary greater than 25000 and Deptno is 20.

Tablename is EMP
All rows to be returned

A
SELECT *
FROM Emp
WHERE job != 'Manager'
AND sal > 25000
AND deptno = 20;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Write a query that returns all employees whose job title is either Clerk or salesman.

Tablename is Emp
All Columns to be returned

A

SELECT *
FROM Emp
WHERE JOB = ‘Clerk’
OR Job = ‘Salesman’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Write a query that returns all employees that are not managers or Salesman and earn a salary greater than or equal to 25000

Tablename is Emp
We only want to see the name column

A
SELECT Name
FROM Emp
WHERE Job != 'Manager'
AND Job != 'Salesman'
AND Salary >= 25000;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Check out the below task and the solution. Why do we use ‘AND Job != ‘Salesman’ rather than ‘OR Job != ‘Salesman’?

Write a query that returns all employees that are not managers or Salesman and earn a salary greater than or equal to 25000

Tablename is Emp
We only want to see the name column

SELECT Name
FROM Emp
WHERE Job != 'Manager'
AND Job != 'Salesman'
AND Salary >= 25000;
A

We use AND rather than OR because by using OR we are cancelling out both clauses

not equal to manager
OR not equal to Salesman

Means that the result set will display all managers and all salesmen.

SQL can parse the command but it will not return what we want. Therefore AND is the only solution. This will cancel out both managers and salesmen.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does Parse mean?

A

To break something down into parts in order to understand each element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the difference between Data Definition language (DDL) and Data manipulation Language (DML)?

A

DDL (Data Definition Language) is used to create and modify the structure of a database.

DML (Data Manipulation Language) is used to access, modify or retrieve the data from the database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly