Load:

Output

Syntax

Links:


The SQL Playground initializes these variables for your use:

$tb = $('#Data table'); $tb is now a jQuery object that holds the table.
$tr = $('#Data table tr:has(td)'); $tr holds all table rows except the header row.
$td = $('#Data table td'); $td holds all table data elements.
$th = $('#Data table th'); $th holds all table header elements.

Note that you don't need to use document ready or its shorthand to work in the Playground.


I've extended jQuery's filter() method so that it accepts a regular expression, which will match against the text content of the elements.

Example:

$td.filter(/^[t-u].+county$/i)
  .css('background', 'orange');
Select all table data that start with the letter t or u and end with the word county (case-insensitive), and give them an orange background.

You cannot accomplish this using contains().

Codecademy has a good SQL course. But it's based on SQLite, which has a slightly different syntax from Access, which we use in-house.


In Unit 2: Queries | 11. Limit, you'll see:

SELECT * FROM movies ORDER BY imdb_rating DESC LIMIT 3;

Note that Access does not have the LIMIT verb. Instead, you would use TOP, like this:

SELECT TOP 3 FROM movies ORDER BY imdb_rating DESC;

In Unit 4: Multiple Tables | 4. Cross Join, you'll see:

SELECT * FROM albums JOIN artists ON albums.artist_id = artists.id;

This is how you create an INNER JOIN in SQLite.

In Access, you have to explicitly include the word INNER:

SELECT * FROM albums INNER JOIN artists ON albums.artist_id = artists.id;

This syntax also works in SQLite, so you might as well include the word INNER whenever you need an INNER JOIN.

Examples

Select all data from Co1516: select * from Co1516
Get the number of records in table So1516: select count(*) as Samples from So1516
Get statistical P data from table An1516: select avg(P) as [Avg P], min(P) as [Min P], max(P) as [Max P], stdev(P) as [Stdev P] from An1516
Note what happens if we don't specify column names: select avg(P), min(P), max(P), stdev(P) from An1516
Round data to 2 decimals: select round(avg(P), 2) as [Avg P] from An1516
Select the top 10 records from So1516, sorted by lab number: select top 10 * from So1516 order by Lab
Same query as above, but sorted in descending order: select top 10 * from So1516 order by Lab desc
Select distinct client names from Pl1516. (Note that they're automatically sorted.) select distinct Name from Pl1516
Select all Wa1516 data where the name contains "rick." (Note that Access does a case-insensitive search.) select * from Wa1516 where name like "%rick%"
Select all Pl1516 data where the lab number is between 100 and 200 (inclusive) and iron is less than 40 ppm: select * from Pl1516 where Lab between 100 and 200 and Fe<40
Select all An1516 data for Clarke County: select * from An1516 where County="059"
Select all An1516 data for Clarke and Hall counties: select * from An1516 where County in ("059", "139")
Include the county name for the previous query: select CountyName, An1516.* from An1516 inner join County on An1516.County=County.County where An1516.County in ("059", "139")
List all plant tissue clients who submitted at least 20 samples in FY16, showing largest submitters first, then ordered by client name: select Name, count(*) as Samples from Pl1516 where Date group by Name having count(*) >= 20 order by 2 desc, Name
List GAP samples per Fiscal Year: transform count(*) select Report from ( select "FY11" as FY,Report from MI1011 where [Report] like "%gap%" union all select "FY12" as FY,Report from MI1112 where [Report] like "%gap%" union all select "FY13" as FY,Report from MI1213 where [Report] like "%gap%" union all select "FY14" as FY,Report from MI1314 where [Report] like "%gap%" union all select "FY15" as FY,Report from MI1415 where [Report] like "%gap%" union all select "FY16 (to-date)" as FY,Report from MI1516 where [Report] like "%gap%" ) group by Report pivot FY
List Soil Test Kits per County per Fiscal Year: transform -sum(b.County is not null) select CountyName from County a left join ( select "FY17 (to-date)" as FY,County from So1617 where field like "0%" union all select "FY16" as FY,County from So1516 where field like "0%" union all select "FY15" as FY,County from So1415 where field like "0%" union all select "FY14" as FY,County from So1314 where field like "0%" union all select "FY13" as FY,County from So1213 where field like "0%" union all select "FY12" as FY,County from So1112 where field like "0%" union all select "FY11" as FY,County from So1011 where field like "0%" union all select "FY10" as FY,County from So0910 where field like "0%" union all select "FY09" as FY,County from So0809 where field like "0%" union all select "FY08" as FY,County from So0708 where field like "0%" ) b on a.County=b.County where b.County group by CountyName pivot FY