This document summarizes all the necessary SQL statements and provides basic examples to help you understand. These notes were produced by a Top 1% IEB candidate in Information Technology in 2020.
Simple SQL Statements
Displaying selected fields: Note:
SELECT <field>, <field> * means all fields
FROM <table>; [] are used if field is
more than one word
Sorting by a field:
SELECT <field (s)> XXX
FROM <table> ASC – Ascending Order
ORDER BY <field> XXX; *default is ASC DESC – Descending Order
Note: You can order by multiple fields!
Displaying data using conditions: #
SELECT * Can be >, < or =
FROM <table> XXX
WHERE <field> # XXX; = ‘Text’
Or can be a digit
Conditions using AND, OR, NOT, BETWEEN … AND …
WHERE Artist = ‘G-Eazy’ AND Title = ‘Scary Nights’;
WHERE Artist = ‘G-Eazy’ OR Artist = ‘NF’;
WHERE NoOfSongs BETWEEN 10 AND 15;
Inserting a record:
INSERT INTO <table> (<field1>, <field2)
VALUES (<value1>, <value2>);
Deleting a record:
DELETE
FROM <table>
WHERE <condition> [AND/OR <condition>]
Changing the details in a field:
UPDATE <table>
SET <column name> = <new value> [,…]
WHERE <column name> = <existing value>
Using quotes in SQL Statements:
Trying to find a name such as O’Brien with an apostrophe in it.
WHERE <name> = ‘O’‘Brien’;
Calculations with fields:
SELECT SSName, SFName, 2015 – AcYear AS [Completion Year]
Deriving a field: (creating a new field using calculations)
SELECT SSName, SFName, 2015 – AcYear AS [Completion Year]
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller NikharRamlakhan. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $8.88. You're not tied to anything after your purchase.