Depending on the information you are analyzing, you may have hundreds or thousands of results returned as a result of your query, and it can be very beneficial to sort and/or filter results for brevity or ease of viewing.
Sorting is a good way to make sure you still have the same number of records and that you dont accidentally redact important information. This can be accomplished using the ORDER BY syntax.
Filtering will limit your records to just those that satisfy a certain criteria. For example, the GROUP BY syntax will limit results to just one record for any particular specified column.
The
WHERE syntax is easily used to only return results that match a
specified value. If you want it to match on the entire value, you can utilize
an equal (=) sign, for example:
WHERE column = 0
If
you are looking for a particular value within a result, like for example a word
within the message body, use LIKE along with a wildcard (%).
For
example:
WHERE column LIKE %yourvalue% where the exact phrase is contained
between two %s.
Should you want to filter on just the beginning or end of a particular phrase or value, you can use LIKE A% for anything that begins with the letter A for example, or LIKE %Z for anything that ends in Z. The % in these examples acts as a wildcard and says any value can come after the A or before the Z respectively.
Several examples have been provided on the following pages.
ORDER BY will return the same number of records but sort them in ascending or descending order. This is a good choice if you do not want to accidentally eliminate any records.
GROUP BY will return just one unique record per column requested. Notice that only one record per user is returned in the result below.
WHERE is selective in that it only returns results that match your particular request. In the statement below, only records where the user is equal to 41 are returned.
WHERE can also be used along with LIKE to match on an entire element or to matching on records that begin or end with a specified value or values. Use % as a wildcard. Notice below we want only those message that contain the word Lloyd.
We could use wildcards to return records with a message body that begin with the letter C.
Or we could use wildcards to return records sent by a user number which ends in the number 2.