SQL

stick to single quotes

SELECT column1, column2, ...
FROM table_name
WHERE condition;

SELECT * FROM Customers
WHERE CustomerID=1
LIMIT 100;

Basic Query

ORDER BY / SORT

ORDER BY ds DESC

MULTI TABLE

SELECT o.OrderID, o.OrderDate, c.CustomerName
FROM Customers AS c, Orders AS o
WHERE c.CustomerName="Around the Horn";

WHERE

 WHERE Country IN ('USA', 'UK', 'Japan')

AND has precedence over OR

INSERT

Update

The where clause will determine how many to update, omitted means all

ADVANCED

Limit and Offset to do pagination

JOINS

  • (INNER) JOIN: Returns records that have matching values in both tables

  • LEFT (OUTER) JOIN: Return all records from the left table, and the matched records from the right table

  • RIGHT (OUTER) JOIN: Return all records from the right table, and the matched records from the left table

  • FULL (OUTER) JOIN: Return all records when there is a match in either left or right table

CASE

Executed in order as shown

Table Structure

CREATE

DELETE

Permanently deletion, be careeefullll

ADVANCED HIVE?

95% SQL syntax, but can query Hadoop turning HiveQL into Map Reduce Jobs

Explode

Make a new row for each list entry

adid_list is an Array of ints

pageid | adid_list becomes=> pageid | adid

1 | [1,2] 1 | 1

​ 1 | 2

HIVE COMMAND LINE

Last updated