Skip to content

Instantly share code, notes, and snippets.

@JestVA
Last active August 29, 2019 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JestVA/1e99a07b6ee26d791a5b664a657be743 to your computer and use it in GitHub Desktop.
Save JestVA/1e99a07b6ee26d791a5b664a657be743 to your computer and use it in GitHub Desktop.
-- SELECT clause
SELECT * FROM Employee
-- WHERE clause
WHERE id = 123 AND is_admin = 'true'
-- values are returned in the order they were asked (like an [ ] from a low level SQL database)
SELECT id, firstname, lastname FROM Employee
-- single quotes are used for string literals
-- Aliases (use the AS keyword to give a table or a column a local name or alias)
SELECT p.productname AS title FROM Product AS p
.where('date', '>', '2016-01-01') // filtering by date in knex
// example of a sql query
select year(date), month(date), avg(price), count(1) from lr_properties
inner join lr_transactions on lr_transactions.lr_property_id = lr_properties.id
where outcode = "E9" group by year(date), month(date);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment