SlideShare a Scribd company logo
Assignment 4
As discussed in the previous assignment, the SELECT statement was dissected, but not all
functionalities were tackled. Today we will analyze the ORDER BY, LIMIT and JOIN keywords
how they influence the base query and what data manipulation possibilities they entail.
In the current assignment only, the marked commands will be used.
1. SELECT
Please refer to Assignment 3 for a brief recap of the SELECT statement. This the core select
clause.
1. JOIN clause
SQLite Joins clause is used to combine records from two or more tables in a database. A JOIN
is a means for combining fields from two tables by using values common to each.
SQL defines three major types of joins βˆ’
β€’ The CROSS JOIN
β€’ The INNER JOIN
β€’ The OUTER JOIN
Before we proceed, let's consider two tables COMPANY and DEPARTMENT. We already have
seen INSERT statements to populate COMPANY table. So just let's assume the list of records
available in COMPANY table.
We also need the DEPARTMENT table.
v The CROSS JOIN
CROSS JOIN matches every row of the first table with every row of the second table. If the
input tables have x and y row, respectively, the resulting table will have x*y row. Because
CROSS JOINs have the potential to generate extremely large tables, care must be taken to
only use them when appropriate.
Using the syntax for CROSS JOIN
SELECT ... FROM table1 CROSS JOIN table2 ...
We will obtain for the DEPARTMENT.EMP_ID, zCOMPANY.NAME, DEPARTMENT.DEPT columns
the following results.
EMP_ID NAME DEPT
---------- ---------- ----------
1 Paul IT Billing
2 Paul Engineering
7 Paul Finance
1 Allen IT Billing
2 Allen Engineering
7 Allen Finance
1 Teddy IT Billing
2 Teddy Engineering
7 Teddy Finance
1 Mark IT Billing
2 Mark Engineering
7 Mark Finance
1 David IT Billing
2 David Engineering
7 David Finance
1 Kim IT Billing
2 Kim Engineering
7 Kim Finance
1 James IT Billing
2 James Engineering
7 James Finance
v The INNER JOIN
INNER JOIN creates a new result table by combining column values of two tables (table1 and
table2) based upon the join-predicate. The query compares each row of table1 with each row
of table2 to find all pairs of rows which satisfy the join-predicate. When the join-predicate is
satisfied, the column values for each matched pair of rows of A and B are combined into a
result row.
An INNER JOIN is the most common and default type of join. You can use INNER keyword
optionally.
Following is the syntax of INNER JOIN –
SELECT ... FROM table1 [INNER] JOIN table2 ON
conditional_expression ...
To avoid redundancy and keep the phrasing shorter, INNER JOIN conditions can be declared
with a USING expression. This expression specifies a list of one or more columns.
SELECT ... FROM table1 JOIN table2 USING (column1, ...) ...
A NATURAL JOIN is similar to a JOIN...USING, only it automatically tests for equality
between the values of every column that exists in both tables βˆ’
SELECT ... FROM table1 NATURAL JOIN table2...
Based on the above tables, you can write an INNER JOIN as follows –
SELECT EMP_ID, NAME, DEPT FROM COMPANY INNER JOIN DEPARTMENT
ON COMPANY.ID = DEPARTMENT.EMP_ID;
The above query will produce the following result βˆ’
EMP_ID NAME DEPT
---------- ---------- ----------
1 Paul IT Billing
2 Allen Engineering
7 James Finance
v The OUTER JOIN
OUTER JOIN is an extension of INNER JOIN. Though SQL standard defines three types of
OUTER JOINs: LEFT, RIGHT, and FULL, SQLite only supports the LEFT OUTER JOIN.
OUTER JOINs have a condition that is identical to INNER JOINs, expressed using an ON,
USING, or NATURAL keyword. The initial results table is calculated the same way. Once the
primary JOIN is calculated, an OUTER JOIN will take any un-joined rows from one or both
tables, pad them out with NULLs, and append them to the resulting table.
Following is the syntax of LEFT OUTER JOIN –
SELECT ... FROM table1 LEFT OUTER JOIN table2 ON
conditional_expression ...
Based on the above tables, you can write an outer join as follows βˆ’
sqlite> SELECT EMP_ID, NAME, DEPT FROM COMPANY LEFT OUTER JOIN
DEPARTMENT
ON COMPANY.ID = DEPARTMENT.EMP_ID;
The above query will produce the following result βˆ’
EMP_ID NAME DEPT
---------- ---------- ----------
1 Paul IT Billing
2 Allen Engineering
Teddy
Mark
David
Kim
7 James Finance
2. ORDER BY clause
If a SELECT statement that returns more than one row does not have an ORDER BY clause,
the order in which the rows are returned is undefined. Or, if a SELECT statement does have
an ORDER BY clause, then the list of expressions attached to the ORDER BY determine the
order in which rows are returned to the user.
Rows are first sorted based on the results of evaluating the left-most expression in the ORDER
BY list, then ties are broken by evaluating the second left-most expression and so on. The
order in which two rows for which all ORDER BY expressions evaluate to equal values are
returned is undefined. Each ORDER BY expression may be optionally followed by one of the
keywords ASC (smaller values are returned first) or DESC (larger values are returned first).
If neither ASC or DESC are specified, rows are sorted in ascending (smaller values first) order
by default.
SQLite considers NULL values to be smaller than any other values for sorting purposes. Hence,
NULLs naturally appear at the beginning of an ASC order-by and at the end of a DESC order-
by. This can be changed using the "ASC NULLS LAST" or "DESC NULLS FIRST" syntax.
Each ORDER BY expression is processed as follows:
Ø If the ORDER BY expression is a constant integer K then the expression is
considered an alias for the K-th column of the result set (columns are numbered
from left to right starting with 1).
Ø If the ORDER BY expression is an identifier that corresponds to the alias of one of
the output columns, then the expression is considered an alias for that column.
Ø Otherwise, if the ORDER BY expression is any other expression, it is evaluated and
the returned value used to order the output rows. If the SELECT statement is a
simple SELECT, then an ORDER BY may contain any arbitrary expressions.
However, if the SELECT is a compound SELECT, then ORDER BY expressions that
are not aliases to output columns must be exactly the same as an expression used
as an output column.
3. LIMIT clause
The LIMIT clause is used to place an upper bound on the number of rows returned by the
entire SELECT statement.
In a compound SELECT, only the last or right-most simple SELECT may contain a LIMIT clause.
In a compound SELECT, the LIMIT clause applies to the entire compound, not just the final
SELECT.
Any scalar expression may be used in the LIMIT clause, so long as it evaluates to an integer
or a value that can be losslessly converted to an integer. If the expression evaluates to a
NULL value or any other value that cannot be losslessly converted to an integer, an error is
returned. If the LIMIT expression evaluates to a negative value, then there is no upper bound
on the number of rows returned. Otherwise, the SELECT returns the first N rows of its result
set only, where N is the value that the LIMIT expression evaluates to. Or, if the SELECT
statement would return less than N rows without a LIMIT clause, then the entire result set is
returned.
The expression attached to the optional OFFSET clause that may follow a LIMIT clause must
also evaluate to an integer, or a value that can be losslessly converted to an integer. If an
expression has an OFFSET clause, then the first M rows are omitted from the result set
returned by the SELECT statement and the next N rows are returned, where M and N are the
values that the OFFSET and LIMIT clauses evaluate to, respectively. Or, if the SELECT would
return less than M+N rows if it did not have a LIMIT clause, then the first M rows are skipped
and the remaining rows (if any) are returned. If the OFFSET clause evaluates to a negative
value, the results are the same as if it had evaluated to zero.
Instead of a separate OFFSET clause, the LIMIT clause may specify two scalar expressions
separated by a comma. In this case, the first expression is used as the OFFSET expression
and the second as the LIMIT expression. This is counter-intuitive, as when using the OFFSET
clause, the second of the two expressions is the OFFSET and the first the LIMIT. This reversal
of the offset and limit is intentional - it maximizes compatibility with other SQL database
systems. However, to avoid confusion, programmers are strongly encouraged to use the form
of the LIMIT clause that uses the "OFFSET" keyword and avoid using a LIMIT clause with a
comma-separated offset.
Excercises:
Use the file provided in the assignment SQL_SAMPLE_DATABASE.txt to create and populate
the tables needed for the exercises, it will be used for the next exercises.
1. Write an SQL statement that returns the Cartesian product of rows from the tables in
the join. Observe the results and specify what happened.
(Hint CROSS JOIN)
2. Write an SQL joins two tables by their common column names. Observe the results
and specify what happened.
(Hint NATURAL JOIN)
3. Write an SQL clause that combines columns from correlated tables that show the name
of the employee and the job title. Observe the results and specify what happened.
(Hint INNER JOIN on JOB_ID)
4. Write an SQL query that fetches all the rows from the specified fields of the left-hand
table. Observe the results and specify what happened.
(Hint LEFT OUTER JOIN employee -> jobs)
5. Same as above but make sure that all entries retrieved from the query do not have
null inside jobs.JOB_TITLE. Is the result similar to a query already called, if so, why?
6. Write an SQL query to retrieve all entries that have salary over 5000 and sort them
descending
(Hint ORDER BY)
7. Write an SQL query to return all entries from employee table that have β€˜JOB_ID’ equal
to SH_CLERK but limit to only 10 of them
(Hint LIMIT)
8. Write an SQL query to return all entries from employee table that have β€˜JOB_ID’ equal
to SH_CLERK but limit to only the last 10
(HINT OFFSET)
Assignment 4

More Related Content

PDF
Assignment 3
Β 
PDF
Sql basics v2
PPTX
Inner join and outer join
PDF
SQL JOINS
PPTX
SQL Tutorial for Beginners
PPTX
Oracle: Joins
PPTX
MySQL JOIN & UNION
PPT
Join sql
Assignment 3
Β 
Sql basics v2
Inner join and outer join
SQL JOINS
SQL Tutorial for Beginners
Oracle: Joins
MySQL JOIN & UNION
Join sql

What's hot (17)

PPTX
SQL JOIN
PPTX
SQL UNION
PPSX
Join query
PPTX
PPT
SQL Introduction to displaying data from multiple tables
PPTX
MULTIPLE TABLES
PPTX
SQL : Structured Query Language
PDF
New Dynamic Array Functions. Excel Tutorial
PPT
SQL Joinning.Database
PPTX
Sql joins inner join self join outer joins
PPT
Sql join
PPTX
Sql(structured query language)
Β 
PDF
Fill series. Data validation. Excel Tutorial
PDF
7. Using Sub Queries
DOC
SQL Joins
PPTX
SQL Fundamentals
PPT
Displaying data from multiple tables
SQL JOIN
SQL UNION
Join query
SQL Introduction to displaying data from multiple tables
MULTIPLE TABLES
SQL : Structured Query Language
New Dynamic Array Functions. Excel Tutorial
SQL Joinning.Database
Sql joins inner join self join outer joins
Sql join
Sql(structured query language)
Β 
Fill series. Data validation. Excel Tutorial
7. Using Sub Queries
SQL Joins
SQL Fundamentals
Displaying data from multiple tables
Ad

Similar to Assignment 4 (20)

PPTX
Sql slid
PPTX
sqlyyybdbyehduheufhuehfuheuwehfiewifhewihfiehfiwf
PPTX
sql joinsubdjbrjdbjrjnfkjcnkrnfknrkfkrfkrfkrk
DOCX
SQL report
PDF
Bt0075 rdbms with mysql 2
PPTX
Day-2 SQL Theory_V1.pptx
PPTX
Day-06-Joining presentation of SQL lecture form uni .pptx
PPTX
DBMS and SQL(structured query language) .pptx
PDF
Chapter9 more on database and sql
PPT
Ms sql server ii
PPT
6.3 my sql queryoptimization_part2
PDF
Sql wksht-6
PPT
Advanced Sql Training
PPT
Joins.ppt
PPTX
Joins in SQL
PDF
3)12th_L8_Join-Set-Operations.pdf
PPTX
Unit_9.pptx
PPTX
Oracle: Joins
PPT
1 introduction to my sql
PPTX
joins and subqueries in big data analysis
Sql slid
sqlyyybdbyehduheufhuehfuheuwehfiewifhewihfiehfiwf
sql joinsubdjbrjdbjrjnfkjcnkrnfknrkfkrfkrfkrk
SQL report
Bt0075 rdbms with mysql 2
Day-2 SQL Theory_V1.pptx
Day-06-Joining presentation of SQL lecture form uni .pptx
DBMS and SQL(structured query language) .pptx
Chapter9 more on database and sql
Ms sql server ii
6.3 my sql queryoptimization_part2
Sql wksht-6
Advanced Sql Training
Joins.ppt
Joins in SQL
3)12th_L8_Join-Set-Operations.pdf
Unit_9.pptx
Oracle: Joins
1 introduction to my sql
joins and subqueries in big data analysis
Ad

Recently uploaded (20)

PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PDF
The Internet -By the Numbers, Sri Lanka Edition
Β 
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PPTX
Funds Management Learning Material for Beg
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PDF
Paper PDF World Game (s) Great Redesign.pdf
PPT
tcp ip networks nd ip layering assotred slides
PPTX
artificial intelligence overview of it and more
PPTX
SAP Ariba Sourcing PPT for learning material
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PPTX
Introduction to Information and Communication Technology
PPTX
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
PDF
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
The Internet -By the Numbers, Sri Lanka Edition
Β 
SASE Traffic Flow - ZTNA Connector-1.pdf
Funds Management Learning Material for Beg
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
Paper PDF World Game (s) Great Redesign.pdf
tcp ip networks nd ip layering assotred slides
artificial intelligence overview of it and more
SAP Ariba Sourcing PPT for learning material
Slides PDF The World Game (s) Eco Economic Epochs.pdf
An introduction to the IFRS (ISSB) Stndards.pdf
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
Cloud-Scale Log Monitoring _ Datadog.pdf
Tenda Login Guide: Access Your Router in 5 Easy Steps
Job_Card_System_Styled_lorem_ipsum_.pptx
The New Creative Director: How AI Tools for Social Media Content Creation Are...
Introduction to Information and Communication Technology
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
Slides PPTX World Game (s) Eco Economic Epochs.pptx

Assignment 4

  • 1. Assignment 4 As discussed in the previous assignment, the SELECT statement was dissected, but not all functionalities were tackled. Today we will analyze the ORDER BY, LIMIT and JOIN keywords how they influence the base query and what data manipulation possibilities they entail. In the current assignment only, the marked commands will be used. 1. SELECT Please refer to Assignment 3 for a brief recap of the SELECT statement. This the core select clause.
  • 2. 1. JOIN clause SQLite Joins clause is used to combine records from two or more tables in a database. A JOIN is a means for combining fields from two tables by using values common to each. SQL defines three major types of joins βˆ’ β€’ The CROSS JOIN β€’ The INNER JOIN β€’ The OUTER JOIN Before we proceed, let's consider two tables COMPANY and DEPARTMENT. We already have seen INSERT statements to populate COMPANY table. So just let's assume the list of records available in COMPANY table.
  • 3. We also need the DEPARTMENT table. v The CROSS JOIN CROSS JOIN matches every row of the first table with every row of the second table. If the input tables have x and y row, respectively, the resulting table will have x*y row. Because CROSS JOINs have the potential to generate extremely large tables, care must be taken to only use them when appropriate. Using the syntax for CROSS JOIN SELECT ... FROM table1 CROSS JOIN table2 ... We will obtain for the DEPARTMENT.EMP_ID, zCOMPANY.NAME, DEPARTMENT.DEPT columns the following results. EMP_ID NAME DEPT ---------- ---------- ---------- 1 Paul IT Billing 2 Paul Engineering 7 Paul Finance 1 Allen IT Billing 2 Allen Engineering 7 Allen Finance 1 Teddy IT Billing 2 Teddy Engineering 7 Teddy Finance 1 Mark IT Billing 2 Mark Engineering 7 Mark Finance 1 David IT Billing 2 David Engineering 7 David Finance 1 Kim IT Billing 2 Kim Engineering 7 Kim Finance 1 James IT Billing 2 James Engineering 7 James Finance
  • 4. v The INNER JOIN INNER JOIN creates a new result table by combining column values of two tables (table1 and table2) based upon the join-predicate. The query compares each row of table1 with each row of table2 to find all pairs of rows which satisfy the join-predicate. When the join-predicate is satisfied, the column values for each matched pair of rows of A and B are combined into a result row. An INNER JOIN is the most common and default type of join. You can use INNER keyword optionally. Following is the syntax of INNER JOIN – SELECT ... FROM table1 [INNER] JOIN table2 ON conditional_expression ... To avoid redundancy and keep the phrasing shorter, INNER JOIN conditions can be declared with a USING expression. This expression specifies a list of one or more columns. SELECT ... FROM table1 JOIN table2 USING (column1, ...) ... A NATURAL JOIN is similar to a JOIN...USING, only it automatically tests for equality between the values of every column that exists in both tables βˆ’ SELECT ... FROM table1 NATURAL JOIN table2... Based on the above tables, you can write an INNER JOIN as follows – SELECT EMP_ID, NAME, DEPT FROM COMPANY INNER JOIN DEPARTMENT ON COMPANY.ID = DEPARTMENT.EMP_ID; The above query will produce the following result βˆ’ EMP_ID NAME DEPT ---------- ---------- ---------- 1 Paul IT Billing 2 Allen Engineering 7 James Finance v The OUTER JOIN OUTER JOIN is an extension of INNER JOIN. Though SQL standard defines three types of OUTER JOINs: LEFT, RIGHT, and FULL, SQLite only supports the LEFT OUTER JOIN. OUTER JOINs have a condition that is identical to INNER JOINs, expressed using an ON, USING, or NATURAL keyword. The initial results table is calculated the same way. Once the primary JOIN is calculated, an OUTER JOIN will take any un-joined rows from one or both tables, pad them out with NULLs, and append them to the resulting table. Following is the syntax of LEFT OUTER JOIN – SELECT ... FROM table1 LEFT OUTER JOIN table2 ON conditional_expression ...
  • 5. Based on the above tables, you can write an outer join as follows βˆ’ sqlite> SELECT EMP_ID, NAME, DEPT FROM COMPANY LEFT OUTER JOIN DEPARTMENT ON COMPANY.ID = DEPARTMENT.EMP_ID; The above query will produce the following result βˆ’ EMP_ID NAME DEPT ---------- ---------- ---------- 1 Paul IT Billing 2 Allen Engineering Teddy Mark David Kim 7 James Finance 2. ORDER BY clause If a SELECT statement that returns more than one row does not have an ORDER BY clause, the order in which the rows are returned is undefined. Or, if a SELECT statement does have an ORDER BY clause, then the list of expressions attached to the ORDER BY determine the order in which rows are returned to the user. Rows are first sorted based on the results of evaluating the left-most expression in the ORDER BY list, then ties are broken by evaluating the second left-most expression and so on. The order in which two rows for which all ORDER BY expressions evaluate to equal values are returned is undefined. Each ORDER BY expression may be optionally followed by one of the keywords ASC (smaller values are returned first) or DESC (larger values are returned first). If neither ASC or DESC are specified, rows are sorted in ascending (smaller values first) order by default. SQLite considers NULL values to be smaller than any other values for sorting purposes. Hence, NULLs naturally appear at the beginning of an ASC order-by and at the end of a DESC order- by. This can be changed using the "ASC NULLS LAST" or "DESC NULLS FIRST" syntax. Each ORDER BY expression is processed as follows:
  • 6. Ø If the ORDER BY expression is a constant integer K then the expression is considered an alias for the K-th column of the result set (columns are numbered from left to right starting with 1). Ø If the ORDER BY expression is an identifier that corresponds to the alias of one of the output columns, then the expression is considered an alias for that column. Ø Otherwise, if the ORDER BY expression is any other expression, it is evaluated and the returned value used to order the output rows. If the SELECT statement is a simple SELECT, then an ORDER BY may contain any arbitrary expressions. However, if the SELECT is a compound SELECT, then ORDER BY expressions that are not aliases to output columns must be exactly the same as an expression used as an output column. 3. LIMIT clause The LIMIT clause is used to place an upper bound on the number of rows returned by the entire SELECT statement. In a compound SELECT, only the last or right-most simple SELECT may contain a LIMIT clause. In a compound SELECT, the LIMIT clause applies to the entire compound, not just the final SELECT. Any scalar expression may be used in the LIMIT clause, so long as it evaluates to an integer or a value that can be losslessly converted to an integer. If the expression evaluates to a NULL value or any other value that cannot be losslessly converted to an integer, an error is returned. If the LIMIT expression evaluates to a negative value, then there is no upper bound on the number of rows returned. Otherwise, the SELECT returns the first N rows of its result set only, where N is the value that the LIMIT expression evaluates to. Or, if the SELECT statement would return less than N rows without a LIMIT clause, then the entire result set is returned. The expression attached to the optional OFFSET clause that may follow a LIMIT clause must also evaluate to an integer, or a value that can be losslessly converted to an integer. If an expression has an OFFSET clause, then the first M rows are omitted from the result set returned by the SELECT statement and the next N rows are returned, where M and N are the values that the OFFSET and LIMIT clauses evaluate to, respectively. Or, if the SELECT would return less than M+N rows if it did not have a LIMIT clause, then the first M rows are skipped and the remaining rows (if any) are returned. If the OFFSET clause evaluates to a negative value, the results are the same as if it had evaluated to zero. Instead of a separate OFFSET clause, the LIMIT clause may specify two scalar expressions separated by a comma. In this case, the first expression is used as the OFFSET expression
  • 7. and the second as the LIMIT expression. This is counter-intuitive, as when using the OFFSET clause, the second of the two expressions is the OFFSET and the first the LIMIT. This reversal of the offset and limit is intentional - it maximizes compatibility with other SQL database systems. However, to avoid confusion, programmers are strongly encouraged to use the form of the LIMIT clause that uses the "OFFSET" keyword and avoid using a LIMIT clause with a comma-separated offset. Excercises: Use the file provided in the assignment SQL_SAMPLE_DATABASE.txt to create and populate the tables needed for the exercises, it will be used for the next exercises. 1. Write an SQL statement that returns the Cartesian product of rows from the tables in the join. Observe the results and specify what happened. (Hint CROSS JOIN) 2. Write an SQL joins two tables by their common column names. Observe the results and specify what happened. (Hint NATURAL JOIN) 3. Write an SQL clause that combines columns from correlated tables that show the name of the employee and the job title. Observe the results and specify what happened. (Hint INNER JOIN on JOB_ID) 4. Write an SQL query that fetches all the rows from the specified fields of the left-hand table. Observe the results and specify what happened. (Hint LEFT OUTER JOIN employee -> jobs) 5. Same as above but make sure that all entries retrieved from the query do not have null inside jobs.JOB_TITLE. Is the result similar to a query already called, if so, why? 6. Write an SQL query to retrieve all entries that have salary over 5000 and sort them descending (Hint ORDER BY) 7. Write an SQL query to return all entries from employee table that have β€˜JOB_ID’ equal to SH_CLERK but limit to only 10 of them (Hint LIMIT) 8. Write an SQL query to return all entries from employee table that have β€˜JOB_ID’ equal to SH_CLERK but limit to only the last 10 (HINT OFFSET)