Skip to content

Instantly share code, notes, and snippets.

@CodeLikeAGirl29
Created April 12, 2023 04:58
Show Gist options
  • Save CodeLikeAGirl29/bb4462c4f6c24260a9ed5c0c322ccdce to your computer and use it in GitHub Desktop.
Save CodeLikeAGirl29/bb4462c4f6c24260a9ed5c0c322ccdce to your computer and use it in GitHub Desktop.

SQL Cheat Sheet, Tips, and Tricks

Tips and Tricks

  • You know that you're in the right database when you see the name of the database at the beginning of the terminal line.
  • If you already know the name of the database you want to connect to, you can write psql name_of_database and that would be equivalent to psql postgres \c name_of_database
  • Remember to steer clear of double quotes around strings in your queries!

SQL Cheat Sheet

Meta Commands

  • \l List databases
  • \c Connect to a database
  • \dt Display Tables in a database
  • \q Quit out of psql to normal terminal

Queries

  • CREATE INSERT INTO worlds (name) VALUES ('Asgard');
  • READ SELECT * FROM herbs;
  • UPDATE UPDATE herbs SET sighting_date = '2021-01-10' WHERE id='1';
  • DELETE DELETE FROM herbs WHERE id='1';

Filters

  • BETWEEN SELECT * FROM trips WHERE start_date BETWEEN '2021-02-01' AND '2021-02-12';
  • LIKE SELECT * FROM books WHERE title LIKE '%ship%';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment