Advertisement
MNikolovski

SQL | Select statement

Sep 13th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. select * from <table name> where <column name> = 'value' (equal)
  2.  
  3. select * from <table name> where <column name> <> 'value' (not equal)
  4.  
  5.  
  6. ### OPERATORS AND WILD CARDS ###
  7.  
  8. IN - Specify a List of values
  9. BETWEEN - Specify a Range
  10. LIKE - Specify a Pattern
  11. NOT - Not in a list, range, etc...
  12.  
  13. % - Specifies zero or more characters
  14. _ - Specifies exactly one character
  15. [] - Any character within the brackets
  16. [^] - Not any character within the brackets
  17.  
  18.  
  19. select * from <table name> where Age = 20 or Age = 21 or Age = 24
  20. select * from <table name> where Age IN (20, 21, 24)
  21.  
  22. select * from <table name> where Age BETWEEN 30 AND 35
  23.  
  24. select * from <table name> where Email LIKE '_@_.com'
  25.  
  26. select * from <table name> where Name LIKE '[MST]%' (selects all the names starting with M, S or T)
  27.  
  28.  
  29.  
  30. ### ORDERING/SORTING THE RESULTS ###
  31.  
  32. select * from <table name> ORDER BY Name
  33. By default, they are sorted in Ascending order. We can sort them in Descending:
  34. select * from <table name> ORDER BY Name DESC
  35.  
  36. We can also sort by multiple columns:
  37. select * from <table name> ORDER BY Name DESC, Age ASC
  38.  
  39.  
  40. select top 10 * from <table name> (selecting the top 10 rows)
  41. select top 5 percent from <table name> (selecting the top 5%)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement