28.10.2014 Views

SQL Injection Attacks and Defense - 2009

SQL Injection Attacks and Defense - 2009

SQL Injection Attacks and Defense - 2009

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

GROUP BY Statement<br />

References • Chapter 10 421<br />

You typically would use the GROUP BY statement when performing an aggregate function<br />

such as SUM against a column in a table. For example, consider that you would like to<br />

perform a query against the following Orders table (Table 10.2) to calculate the total cost<br />

for customer Anthony Anteater.<br />

Table 10.2 Orders Table<br />

ID Customer Product Cost<br />

1 Gary Smith Scooter 7000<br />

2 Anthony Anteater Porsche 911 65000<br />

3 Simon Sez Citron C2 1500<br />

4 Anthony Anteater Oil 10<br />

5 Anthony Anteater Super Alarm 100<br />

The following statement will automatically group orders received from user Anthony<br />

Anteater <strong>and</strong> then perform a SUM operation against the Cost column:<br />

SELECT customer,SUM(cost) FROM orders WHERE customer = 'Anthony Anteater'<br />

GROUP BY customer<br />

ORDER BY Clause<br />

You use the ORDER BY clause to sort the results of a SELECT statement by a specific<br />

column; it accepts either a column name or a number as a m<strong>and</strong>atory parameter. It is possible<br />

to add the keyword ASC or DESC to sort the results in an ascending or descending order,<br />

respectively. The following <strong>SQL</strong> statement will select the cost <strong>and</strong> product columns from<br />

the orders table <strong>and</strong> sort the results by the cost column in descending order:<br />

SELECT cost, product FROM orders ORDER BY cost DESC<br />

Limiting the Result Set<br />

When performing <strong>SQL</strong> injection attacks you will often need to limit the number of table<br />

rows returned by your injected query (e.g., when extracting data via error messages).<br />

The syntax for selecting a specific row from a table varies among database platforms. Table 10.3<br />

details the <strong>SQL</strong> syntax for selecting the first <strong>and</strong> fifth rows from the tblUsers table.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!