SHARE
TWEET

Untitled

a guest Aug 24th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # SQL SELECT COMMAND ....
  2.  
  3. SELECT column FROM table;
  4. SELECT ___ FROM ___;
  5.  
  6. SELECT * FROM customers;
  7.  
  8. SELECT customers.first_name, customers.last_name FROM customers;
  9.  
  10. # Alias to rename
  11.  
  12. SELECT customers.first_name AS "First name", customers.last_name AS "Last name" FROM customers;
  13.  
  14. # WHERE for filtering goes after the table we are selecting from
  15.  
  16. SELECT customers.first_name AS "First name", customers.last_name AS "Last name" FROM customers
  17. WHERE customers.first_name = 'Rolf;
  18.  
  19. # Filtering selecting Two users
  20. SELECT customers.first_name AS "First name", customers.last_name AS "Last name" FROM customers
  21. WHERE customers.first_name = 'Rolf' OR customer.last_name ='Watson';
  22.  
  23. SELECT customers.first_name AS "First name", customers.last_name AS "Last name" FROM customers
  24. WHERE customers.first_name = 'Rolf' AND customer.last_name ='Watson';
  25.  
  26. # LIMIT - Limiting the number of results
  27.  
  28. SELECT customers.first_name AS "First name", customers.last_name AS "Last name" FROM customers
  29. LIMIT 1;
  30.  
  31. # UPDATE data in a table
  32.  
  33. UPDATE table SET column WHERE new_value;
  34.  
  35.  
  36. UPDATE items SET price=4.00 WHERE id=3;
  37.  
  38. # DELETE Delete Rows from tables
  39.  
  40. DELETE FROM purchases WHERE item_id=4;
  41. DELETE FROM items WHERE id=4;
  42.  
  43. # SQL Wildcards for filtering unknowns
  44.  
  45. SELECT * FROM customers WHERE last_name LIKE '____';
  46. SELECT * FROM customers WHERE last_name LIKE '%';
  47. SELECT * FROM customers WHERE last_name LIKE '%t%';
  48. SELECT * FROM customers WHERE last_name LIKE '%t_%'; // One charecter after the t
  49.  
  50.  
  51. :JOINS:
  52.  
  53. Retrieve data from multiple tables at once
  54. Like sets set operations
  55.  
  56. SET INTERSECT is Like INNER JOIN:
  57.  - Inner JOIN selects rows from table 1 and table 2 where they match the selecting column
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top