Skip to content

Instantly share code, notes, and snippets.

@jasonlucas907
Last active December 12, 2017 19:10
Show Gist options
  • Save jasonlucas907/4ce6f641c16d5a7e25be60d343cbd72d to your computer and use it in GitHub Desktop.
Save jasonlucas907/4ce6f641c16d5a7e25be60d343cbd72d to your computer and use it in GitHub Desktop.

SQL - Sequel

SQL is alnguage to get and manipulate date from a database like PostgreSQL.

Data Types:(not all)


-text
-numeric
-date

Queries

Select all information from a table.

SELECT * FROM (table_name);

Select only select information from a table.

SELECT (example-info) FROM (table_name);

SELECT (example-info), (example-info) FROM (table_name);

'AS' keyword. Alter the name of a returned column. This will not change the name in the database.

SELECT (example_info) AS ("new name") FROM (table_name);

'WHERE' keyword. Use WHERE to create a conditional return.

SELECT (example_info) FROM (example_table) WHERE (example_info) = (parameter);

Operators: =, !=, <, <=, >, >=

Multiple Condtions: AND & OR

'IN' keyword. Use this to retireve multiple parameters.

SELECT (example_info) FROM (table) WHERE (example_info) IN ("example", "example", "example");

'BETWEEN & AND' keyword. Use this to retireve information in a select range.

SELECT (example_info) FROM (table) WHERE (example_info) BETWEEN ("example") AND ("example");

'LIKE' keyword. This can be used to find anything that includes a parameter.

SELECT (example_info) FROM (table) WHERE (example_info) LIKE ("example");

Use % for a partial match. Example: ("%ample");

'IS NULL & IS NOT NULL' keyword.

SELECT (example_info) FROM (table) WHERE (example_info) IS NULL;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment