information resource engineering sql3. recap- sql rules and conventions certain ‘keywords’ are...

40
Information Resource Engineering SQL3

Upload: melinda-simon

Post on 13-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Information Resource Engineering

SQL3

Page 2: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Recap-SQL Rules and Conventions Certain ‘keywords’ are ‘reserved’ and have

special meaning in SQL e.g.: SELECT, FROM

All SQL keywords are shown in UPPERCASE Names can be made from:

SQL statements all end with a ‘;’

Character RangeLetter A-Z a-zNumber 0-9Other _

Page 3: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Recap-SELECT SELECT statements implement the

PROJECT operation in relational algebra.

Column names can be in any order

SELECT column_name, column_name...FROM table_name;

Page 4: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Recap-WHERE WHERE statements implement the

Select (sometimes called the Restrict) operation in relational algebra.

= equals

< less than

> greater than

<> not equals

!= not equals

Page 5: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Recap- AND’s, OR’s and NOT’sCourse Code

CourseDescription Cost Type Credit Value

Day Taught

Campus

C002 Intro to Word 60 Word Proc. 5 Wed Rhondda

C003 Intro to Excel 60 Sp.Sheet 5 Thur Ponty

C004 Advanced Web 200 Web 15 Wed Ponty

C005 Advanced Access 250 Database 15 Thur Ponty

C006 Intermediate Word

150 Word Proc. 10 Wed Ponty

Course

SELECT CourseCode,CreditValue,DayTaught,Campus

FROM Course

WHERE CreditValue=5 AND NOT (DayTaught=‘Thur’ OR Campus = ‘Rhondda’);

Page 6: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

BETWEEN

SELECT *

FROM Course

WHERE Cost >= 150 AND Cost <= 250;

SELECT *

FROM Course

WHERE Cost BETWEEN 150 AND 250;

Can also be written as:

Page 7: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

BETWEEN

SELECT *

FROM Course

WHERE CourseCode BETWEEN ‘C001’ AND ‘C004’;

We can also use BETWEEN in comparisons between other data types:

But be careful, as the ‘ordering’ recognised by SQL may differ from your interpretation.

SELECT *

FROM Course

WHERE CourseCode BETWEEN ‘C001’ AND ‘C0004’;

Page 8: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

BETWEEN

SELECT CourseCode,CourseDescription,Cost

FROM Course

WHERE CourseCode BETWEEN ‘C002’ AND ‘C004’;

SELECT CourseCode,CourseDescription,CostFROM Course

WHERE CourseCode BETWEEN ‘C002’ AND ‘C0004’;

CourseCode

CourseDescription

Cost

C002 Intro to Word £60.00

C003 Intro to Excel £60.00

C004 Advanced Web £200.00

CourseCode

CourseDescription

Cost

C002 Intro to Word £60.00

Page 9: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

IN

SELECT *

FROM Course

WHERE Type = ‘Word Proc.’ OR Type = ‘Web’ OR Type = ‘Database’;

SELECT *

FROM Course

WHERE Type IN (‘Word Proc.’,‘Web’,‘Database’);

Can also be written as:

Page 10: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

LIKE

Course Code

CourseDescription Tutor

C001 Networks Advanced

A. Cable

C002 Intro to Word F.Smith

C003 Intro to Excel B.Bloggs

C004 Advanced Web M. Lamb

C005 Advanced Access L. Lamb

C006 Intermediate Word L.Ranger

Sometimes we want to query on ‘part’ of an attribute (field)

What if we wanted a list of all the ‘advanced’ courses

We can use ‘LIKE’ combined with a ‘wildcard’

The ‘wildcard’ used in Access SQL is *

Page 11: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

LIKE

Course Code

CourseDescription Tutor

C001 Networks Advanced

A. Cable

C002 Intro to Word F.Smith

C003 Intro to Excel B.Bloggs

C004 Advanced Web M. Lamb

C005 Advanced Access L. Lamb

C006 Intermediate Word

L.Ranger

However, we have to think carefully about where we place the wildcard.

SELECT CourseCode,CourseDescription

FROM Course

WHERE CourseDescription LIKE ‘*Advanced’;

Resulting Output

1 Row

Course Code

CourseDescription

C001 Networks Advanced

Page 12: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

LIKE

Course Code

CourseDescription Tutor

C007 Networks Advanced

A. Cable

C002 Intro to Word F.Smith

C003 Intro to Excel B.Bloggs

C004 Advanced Web M. Lamb

C005 Advanced Access L. Lamb

C006 Intermediate Word

L.Ranger

However, we have to think carefully about where we place the wildcard.

SELECT CourseCode,CourseDescription

FROM Course

WHERE CourseDescription LIKE ‘Advanced*’;

Resulting Output

2 Rows

Course Code

CourseDescription

C004 Advanced Web

C005 Advanced Access

Page 13: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

LIKE

Course Code

CourseDescription Tutor

C001 Networks Advanced

A. Cable

C002 Intro to Word F.Smith

C003 Intro to Excel B.Bloggs

C004 Advanced Web M. Lamb

C005 Advanced Access L. Lamb

C006 Intermediate Word

L.Ranger

However, we have to think carefully about where we place the wildcard.

SELECT CourseCode,CourseDescription

FROM Course

WHERE CourseDescription LIKE ‘*Advanced*’;

Resulting Output

3 Rows

Course Code

CourseDescription

C001 Networks Advanced

C004 Advanced Web

C005 Advanced Access

Page 14: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Calculated Fields To use a calculated (derived) field, you

specify an SQL expression in the SELECT list. An SQL expression can involve addition,

subtraction, multiplication and division.

SELECT Name, AnnualSalary/12

FROM Employee;

For example:

Will output the monthly salary of employees

(Where AnnualSalary = the annual (yearly) salary)

Page 15: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Calculated Fields Parentheses can be used to build

complex expressions.

SELECT Name, (AnnualSalary – (AnnualSalary*0.3))/12

FROM Employee;

For example, to output the net monthly salary of employees (after tax at 30% has been subtracted) we can use:

Page 16: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Calculated Fields More than one table column can be

used in a calculated column.

SELECT Name,(((AnnualSalary – (AnnualSalary*0.3))/12)+MonthlyExpenses)

FROM Employee;

For example, to output the net monthly salary of employees (after tax at 30% has been subtracted and monthly expenses added) we can use:

Where both AnnualSalary and Expenses are attributes within the Table Employee.

Page 17: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Calculated Fields We can use calculated fields in the

WHERE part of our SQL statement:

SELECT Name, AnnualSalary/12,

FROM Employee

WHERE AnnualSalary/12 > 2000.00;

For example, to output those employees that have a monthly salary of more than £2,000, we can use

Page 18: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Calculated Fields Using the following table, produce the SQL statement that would output all those employees that earn more than £2000 each month (Bonus = their Monthly Bonus)

Monthly Salary = (AnnualSalary/12) + Bonus

EmpNo

NameAnnualSalary

Bonus

E001 Fred 18,000.00 100.00

E002 BamBam

27,600.00 150.00

E003 Barney 20,400.00 200.00

E004 Wilma 24,000.00 400.00

E006 Pebbles 14,400.00 150.00

E007 Betty 16,800.00 150.00

E009 Dino 30,000.00 300.00

Employee

Page 19: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Calculated Fields

SELECT Name, AnnualSalary,Bonus

FROM Employee

WHERE ((AnnualSalary/12) + Bonus) > 2000.00;

EmpNo

NameAnnualSalary

Bonus

E001 Fred 18,000.00 100.00

E002 BamBam

27,600.00 150.00

E003 Barney 20,400.00 200.00

E004 Wilma 24,000.00 400.00

E006 Pebbles 14,400.00 150.00

E007 Betty 16,800.00 150.00

E009 Dino 30,000.00 300.00

Employee

NameAnnualSalary

Bonus

BamBam

27,600.00 150.00

Wilma 24,000.00 400.00

Dino 30,000.00 300.00

Resulting Output

Page 20: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Column Aliases When displaying the result of a query, the

selected column’s name is used as the heading. However, when using a Calculated Field the

‘column’ heading is not particularly descriptive:

SELECT Name, AnnualSalary/12

FROM Employee;Name Expr1001

Fred 1,500.00

BamBam 2,300.00

Barney 1,700.00

Wilma 2,000.00

Pebbles 1,200.00

Betty 1,400.00

Dino 2,500.00

Resulting Output

Page 21: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Column Aliases Even for those ‘columns’ specified as

attributes in the table this can be rather cryptic.

EmpNo Name

E001 Fred

E002 BamBam

E003 Barney

E004 Wilma

E006 Pebbles

E007 Betty

E009 Dino

SELECT EmpNo, Name

FROM Employee;

Resulting Output

Page 22: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Column Aliases You can change a columns heading by

using an Alias. A column alias gives the column an

alternative heading on output.

Any Alias with a ‘blank’ or ‘space’ must be surrounded by quotes. Unfortunately, these also appear in the heading output.

SELECT columnname, columnname AS aliasname, …

FROM tablename

Page 23: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Column Aliases

EmpNo

NameAnnualSalary

Bonus

E001 Fred 18,000.00 100.00

E002 BamBam

27,600.00 150.00

E003 Barney 20,400.00 200.00

E004 Wilma 24,000.00 400.00

E006 Pebbles 14,400.00 150.00

E007 Betty 16,800.00 150.00

E009 Dino 30,000.00 300.00

Employee Resulting Output

SELECT EmpNo AS ‘Employee Number’, (AnnualSalary/12) AS “Monthly Salary”

FROM Employee;

‘Employee Number’

“Monthly Salary”

E001 1,500.00

E002 2,300.00

E003 1,700.00

E004 2,000.00

E006 1,200.00

E007 1,400.00

E009 2,500.00

Page 24: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Column AliasesUsing the following table, output a report with headings

Employee Number Name Monthly Bonus

For those employees that have a bonus equal to or greater than £100.

EmpNo NameAnnualSalary

Bonus

E001 Fred 18,000.00 100.00

E002 BamBam 27,600.00 150.00

E003 Barney 20,400.00 200.00

E004 Wilma 24,000.00 400.00

E006 Pebbles 14,400.00 150.00

E007 Betty 16,800.00 150.00

E009 Dino 30,000.00 300.00

Employee

Page 25: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Column Aliases

EmpNo

NameAnnualSalary

Bonus

E001 Fred 18,000.00 100.00

E002 BamBam

27,600.00 150.00

E003 Barney 20,400.00 200.00

E004 Wilma 24,000.00 400.00

E006 Pebbles 14,400.00 150.00

E007 Betty 16,800.00 150.00

E009 Dino 30,000.00 300.00

Employee Resulting Output

SELECT EmpNo AS ‘Employee Number’, Name, Bonus AS ‘Monthly Bonus’

FROM Employee

WHERE Bonus >=100;

‘Employee Number’

Name‘Monthly Bonus’

E001 Fred 100.00

E002 BamBam 150.00

E003 Barney 200.00

E004 Wilma 400.00

E006 Pebbles 150.00

E007 Betty 150.00

E009 Dino 300.00

Page 26: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Duplicate Rows Unless specified, the results of a query

will be returned with duplicate rows.

To eliminate duplicate values, we must include the DISTINCT clause in the SELECT command.

Page 27: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Duplicate Rows

EmpNoDeptNo

Job

Fred D1 Salesperson

Wilma D2 Manager

Barney D3 Programmer

Betty D2 Salesperson

Pebbles D3 Programmer

BamBam D1 Analyst

Dino D4 Manager

SELECT DeptNo

FROM Employee;

Resulting OutputEmployee

DeptNo

D1

D2

D3

D2

D3

D1

D4

Page 28: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Using Distinct

EmpNoDeptNo

Job

Fred D1 Salesperson

Wilma D2 Manager

Barney D3 Programmer

Betty D2 Salesperson

Pebbles D3 Programmer

BamBam D1 Analyst

Dino D4 Manager

SELECT DISTINCT DeptNo

FROM Employee;

Resulting OutputEmployee

DeptNo

D1

D2

D3

D4

Page 29: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Ordering Output Usually, the order of rows returned in a

query result is undefined.

The ORDER BY clause sets the sequence for outputting selected information.

This can either be: Ascending order ASC (default)

Descending order DESC.

If used the ORDER BY must always be the last clause in the SELECT command.

Page 30: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Ordering Output

EmpNoDeptNo

Job

Fred D1 Salesperson

Wilma D2 Manager

Barney D3 Programmer

Betty D2 Salesperson

Pebbles D3 Programmer

BamBam D1 Analyst

Dino D4 Manager

SELECT *

FROM Employee

ORDER BY DeptNo;

Resulting OutputEmployee

EmpNoDeptNo

Job

Fred D1 Salesperson

BamBam D1 Analyst

Wilma D2 Manager

Betty D2 Salesperson

Barney D3 Programmer

Pebbles D3 Programmer

Dino D4 Manager

Page 31: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Ordering Output We can use the WHERE statement to select rows

before we order them.

EmpNo

Name AnnualSalary

E003 Barney 20,400.00

E004 Wilma 24,000.00

E002 BamBam 27,600.00

E009 Dino 30,000.00

EmployeeResulting Output

SELECT EmpNo, Name, AnnualSalary

FROM Employee

WHERE AnnualSalary > 20000

ORDER BY AnnualSalary;

EmpNo

NameAnnualSalary

Bonus

E001 Fred 18,000.00 100.00

E002 BamBam

27,600.00 150.00

E003 Barney 20,400.00 200.00

E004 Wilma 24,000.00 400.00

E006 Pebbles 14,400.00 150.00

E007 Betty 16,800.00 150.00

E009 Dino 30,000.00 300.00

Page 32: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Ordering Output

EmpNo

Name AnnualSalary

E009 Dino 30,000.00

E002 BamBam 27,600.00

E004 Wilma 24,000.00

E003 Barney 20,400.00

EmployeeResulting Output

SELECT EmpNo, Name, AnnualSalary

FROM Employee

WHERE AnnualSalary > 20000

ORDER BY AnnualSalary DESC;

EmpNo

NameAnnualSalary

Bonus

E001 Fred 18,000.00 100.00

E002 BamBam

27,600.00 150.00

E003 Barney 20,400.00 200.00

E004 Wilma 24,000.00 400.00

E006 Pebbles 14,400.00 150.00

E007 Betty 16,800.00 150.00

E009 Dino 30,000.00 300.00

Page 33: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Ordering Output

EmployeeEmpNo

NameAnnualSalary

Bonus

E001 Fred 18,000.00 100.00

E002 BamBam

27,600.00 150.00

E003 Barney 20,400.00 200.00

E004 Wilma 24,000.00 400.00

E006 Pebbles 14,400.00 150.00

E007 Betty 16,800.00 150.00

E009 Dino 30,000.00 300.00

Using the following table, output those employees that have an Annual Salary of less than £20,000. Output Name and Annual Salary in Descending Annual Salary order

Page 34: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Ordering Output

Name AnnualSalary

Pebbles 14,400.00

Betty 16,800.00

Fred 18,000.00

EmployeeResulting Output

SELECT Name, AnnualSalary

FROM Employee

WHERE AnnualSalary < 20000

ORDER BY AnnualSalary DESC;

EmpNo

NameAnnualSalary

Bonus

E001 Fred 18,000.00 100.00

E002 BamBam

27,600.00 150.00

E003 Barney 20,400.00 200.00

E004 Wilma 24,000.00 400.00

E006 Pebbles 14,400.00 150.00

E007 Betty 16,800.00 150.00

E009 Dino 30,000.00 300.00

Page 35: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Ordering Output We don’t have to output the column we are

ordering on.

EmpNo

NameAnnualSalary

Bonus

E001 Fred 18,000.00 100.00

E002 BamBam

27,600.00 150.00

E003 Barney 20,400.00 200.00

E004 Wilma 24,000.00 400.00

E006 Pebbles 14,400.00 150.00

E007 Betty 16,800.00 150.00

E009 Dino 30,000.00 300.00

Employee Resulting Output

SELECT Name, AnnualSalary

FROM Employee

ORDER BY Bonus;

NameAnnualSalary

Fred 18,000.00

BamBam

27,600.00

Pebbles 14,400.00

Betty 16,800.00

Barney 20,400.00

Dino 30,000.00

Wilma 24,000.00

Page 36: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Ordering Output We can order on more than one column

EmpNo

NameAnnualSalary

Bonus

E001 Fred 18,000.00 100.00

E002 BamBam

27,600.00 150.00

E003 Barney 20,400.00 200.00

E004 Wilma 24,000.00 400.00

E006 Pebbles 14,400.00 150.00

E007 Betty 16,800.00 150.00

E009 Dino 30,000.00 300.00

Employee Resulting Output

SELECT *

FROM Employee

ORDER BY Bonus,AnnualSalary;

EmpNo

NameAnnualSalary

Bonus

E001 Fred 18,000.00 100.00

E006 Pebbles 14,400.00 150.00

E007 Betty 16,800.00 150.00

E002 BamBam

27,600.00 150.00

E003 Barney 20,400.00 200.00

E009 Dino 30,000.00 300.00

E004 Wilma 24,000.00 400.00

Page 37: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Ordering OutputUsing the following table, produce the SQL statement that would output the employee name, department number, job and monthly salary in job then descending salary order.

Employee

EmpNo

NameDeptNo

JobMonthlySalary

E001 Fred D1 Salesperson

1,500.00

E002 BamBam

D1 Analyst 2,300.00

E003 Barney D3 Programmer

1,700.00

E004 Wilma D2 Manager 2,000.00

E006 Pebbles

D3 Programmer

1,200.00

E007 Betty D2 Salesperson

1,400.00

E009 Dino D4 Manager 2,500.00

Page 38: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Ordering OutputEmployee

EmpNo

NameDeptNo

JobMonthlySalary

E001 Fred D1 Salesperson

1,500.00

E002 BamBam

D1 Analyst 2,300.00

E003 Barney D3 Programmer

1,700.00

E004 Wilma D2 Manager 2,000.00

E006 Pebbles

D3 Programmer

1,200.00

E007 Betty D2 Salesperson

1,400.00

E009 Dino D4 Manager 2,500.00

SELECT Name, DeptNo, Job,MonthlySalary

FROM Employee

ORDER BY Job, MonthlySalary DESC;

Page 39: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

Ordering Output

Resulting Output

SELECT Name, DeptNo, Job,MonthlySalary

FROM Employee

ORDER BY Job, MonthlySalary DESC;

NameDeptNo

JobMonthlySalary

BamBam

D1 Analyst 2,300.00

Dino D4 Manager 2,500.00

Wilma D2 Manager 2,000.00

Barney D3 Programmer

1,700.00

Pebbles D3 Programmer

1,200.00

Fred D1 Salesperson

1,500.00

Betty D2 Salesperson

1,400.00

Page 40: Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,

In Conclusion We have covered:

BETWEEN, IN and LIKE

Deleting Information.

Column Aliases

Dealing with duplicate rows (DISTINCT)

Ordering output (ORDER BY)