SQL
sql.js
Allow others to view your program.
Allow others to see your code. Otherwise, they will only be able to run your program.
Prevent others from modifying the embedded code.
Show the file tree in the embedded editor.
This is the exercise prompt your students will see when they open this assignment
SELECT * FROM Table;
SELECT field1, field2 FROM Table;
-- Basic WHERE clause SELECT * FROM Table WHERE condition; -- Compound WHERE clauses SELECT * FROM Table WHERE condition1 AND condition2;
= equal < less than > greater than <> not equal IN (a, b, c) Value is in a list BETWEEN x AND y Value is between x and y LIKE "%" String matches a pattern
"A%" (words starting with "A") "%a" (words ending with "a") "%a%" (words with "a" in it)
// Sort by a field name ORDER BY field_name; -- Sort by a field name in reverse ORDER BY field_name DESC; -- Sort by a field and then sort by a 2nd field when the 1st field is equal ORDER BY field_1, field_2;
SELECT field_name AS "Field Name" SELECT first_name AS "First Name"
-- Select all fields in both tables combined. SELECT * FROM TableA JOIN TableB; -- Select only the rows in the joined table where the ids match SELECT * FROM TableA JOIN TableB WHERE TableA.id = TableB.id; -- Select only the relevant columns from each table -- Where their ids match SELECT TableA.value, TableB.value FROM TableA JOIN TableB WHERE TableA.id = TableB.id;
-- Return the number of rows in Table SELECT COUNT(*) FROM Table; -- Return the number of houses and name -- the column "Num Houses" SELECT COUNT(*) As "Num Houses" FROM House;
-- Syntax for grouping and counting SELECT field_name, COUNT(*) FROM Table GROUP BY field_name;
-- You use HAVING instead of WHERE if you are -- filtering after a GROUP BY SELECT field_name, COUNT(*) FROM Table GROUP BY field_name HAVING condition;
-- Use LIMIT after any query to limit the number of results SELECT * FROM Table LIMIT 10; -- Ex) Show the 5 highest values only SELECT field_name, COUNT(*) FROM Table GROUP BY field_name ORDER BY COUNT(*) DESC LIMIT 5;
No slides available for this video
Admin Only. Not visible to customers
A collaborative program is a program you can work on with a partner or group of people. The program shows up in all of your sandbox pages, and when any of you save code, it will save it for each person.
Want to use your CodeHS code outside of CodeHS? Use this embed code to get started.
codehs.html
on your desktopcodehs.html
on your desktopSQL
sql.js