Select Syntax
SELECT [ALL | DISTINCT] select_expr, select_expr, ... FROM table_reference [WHERE where_condition] [GROUP BY col_list] [ CLUSTER BY col_list | [DISTRIBUTE BY col_list] [SORT BY col_list] ] [LIMIT number]
- A SELECT statement can be part of a union query or a subquery of another query.
- table_reference indicates the input to the query. It can be a regular table, a join construct or a subquery.
- Simple query. For example, the following query retrieves all columns and all rows from table t1.
SELECT * FROM t1
- Where clause – The where condition is a boolean expression. For example, the following query returns only those sales records which have an amount greater than 10 from the US region. Hive does not support IN, EXISTS or subqueries in the WHERE clause.
SELECT * FROM sales WHERE amount > 10 AND region = "US"
- The ALL and DISTINCT options specify whether duplicate rows should be returned. If none of these options are given, the default is ALL (all matching rows are returned). DISTINCT specifies removal of duplicate rows from the result set.
hive> SELECT col1, col2 FROM t1
1 3
1 3
1 4
2 5
hive> SELECT DISTINCT col1, col2 FROM t1
1 3
1 4
2 5
hive> SELECT DISTINCT col1 FROM t1
1
2
- Partition based queries. In general, a SELECT query scans the entire table (other than for sampling). If a table created using the PARTITIONED BY clause, a query can do input pruning and scan only a fraction of the table relevant to the query. Hive currently does input pruning only if the partition predicates are specified in the WHERE clause closest to the table_reference in the FROM clause. For example, if table page_views is partitioned on column date, the following query retrieves rows for just one day 2008-03-31.
SELECT page_views.*
FROM page_views
WHERE page_views.date >= '2008-03-01' AND page_views.date <= '2008-03-31'
- See also Group By
- See also Sort By / Cluster By / Distribute By / Order By
- Having – Hive currently does not support HAVING clause. A similar effect can be gotten by using a subquery. For example,
SELECT col1 FROM t1 GROUP BY col1 HAVING SUM(col2) > 10
can be rewritten as
SELECT col1 FROM (SELECT col1, SUM(col2) AS col2sum FROM t1 GROUP BY col1) t2 WHERE t2.col2sum > 10
- Limit indicates the number of rows to be returned. The rows returned are chosen at random. The following query returns 5 rows from t1 at random.
SELECT * FROM t1 LIMIT 5
- Top k queries. The following query returns the top 5 sales records wrt amount.
SET mapred.reduce.tasks = 1 SELECT * FROM sales SORT BY amount DESC LIMIT 5
- A SELECT statement can take regex-based column specification.
- We use java regex syntax. Try http://www.fileformat.info/tool/regex.htm for testing purposes.
- The following query select all columns except ds and hr.
SELECT `(ds|hr)?+.+` FROM sales
Onload of page my antivirus put alert, check pls.
Thanks
Saurooon
Authentic words, some authentic words man. Thanx for making my day!!
Good Blog Post…
Have a look at this Post on this Blog…
I really enjoyed reading your article, keep up posting such exciting stuff!
6psPwX yczphivzpzew, [url=http://afipqmxjecwp.com/]afipqmxjecwp[/url], [link=http://boqcykfsixyx.com/]boqcykfsixyx[/link], http://xoeltvkeloty.com/
How did you make this template? I got a blog as well and my template looks kinda bad so people don’t stay on my blog very long :/.
XBYT8d oxaiipudeuji, [url=http://xqwcwyniebww.com/]xqwcwyniebww[/url], [link=http://kyzrqrxfdrzp.com/]kyzrqrxfdrzp[/link], http://hygzksgxisxp.com/
12PeTj irgepubgonqf, [url=http://llblfgeetdol.com/]llblfgeetdol[/url], [link=http://zwshzunycnki.com/]zwshzunycnki[/link], http://gvfmowldhspe.com/
I really liked reading your post!. Quallity content. With such a valuable blog i believe you deserve to be ranking even higher in the search engines
. Check out the link in my name. That links to a tool that really helped me rank high in google. This way even more people can enjoy your posts and nothing beats a big audiance
ihdtubix…
ihdtubix…