Impala where clouse with bigInt - hive

we have a hive table that has a column in a bigInt type, so I tried to use a simple select query with use where clouse to that column.
Impala
select * form table where id = 1081145387194379590;
but it returns 0 results.
then I tried as below way
select * from dmi.ti_fact_cem_detail_ufdr_other_d
where id = CAST(1081145387194379590 AS BIGINT);
so still I'm getting 0 results.
also my table contain few rows with id = 0;
when I tried below query
select * from dmi.ti_fact_cem_detail_ufdr_other_d
where id = 0;
it returns correct results.
finally I tried the all above queries with Hive
and it returns correct results.
is there anything I missed here

Related

show columns in CTE returns an error - why?

I have a show columns query that works fine:
SHOW COLUMNS IN table
but it fails when trying to put it in a CTE, like this:
WITH columns_table AS (
SHOW COLUMNS IN table
)
SELECT * from columns_table
any ideas why and how to fix it?
Using RESULT_SCAN:
Returns the result set of a previous command (within 24 hours of when you executed the query) as if the result was a table. This is particularly useful if you want to process the output from any of the following:
SHOW or DESC[RIBE] command that you executed.
SHOW COLUMNS IN ...;
WITH columns_table AS (
SELECT *
FROM table(RESULT_SCAN(LAST_QUERY_ID()))
)
SELECT *
FROM columns_table;
CTE requires select clause and we cannot use SHOW COLUMN IN CTE's and as a alterative use INFORMATION_SCHEMA to retrieve metadata .Like below:
WITH columns_table AS (
Select * from INTL_DB.INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='CURRENCIES'
)
SELECT * from columns_table;

Filtering 'Where In' Queries by 'Is Not Null' in Big Query

I am attempting to query a table in BigQuery programmatically, and have a WHERE-IN clause that I would like to support having NULL as the value. Current Query looks like:
SELECT * FROM DATASET.TABLE_NAME WHERE HIT_DATE = 'YYYY-MM-DD' AND ID IN (LIST_OF_IDS);
I am wondering if there is a way so that I can query everything from the table for a specific date in the case that the LIST_OF_IDS input is NULL (The idea being that I want to support choosing between an inputting of a list of ids or return everything if no list of ids are given).
I tried
SELECT * FROM DATASET.TABLE_NAME WHERE HIT_DATE = 'YYYY-MM-DD' AND ID IN (LIST_OF_IDS) IS NOT NULL;
But got this error thrown at me:
Syntax error: Expression to the left of IS must be parenthesized
If I understand correctly you are looking for this :
SELECT *
FROM DATASET.TABLE_NAME
WHERE HIT_DATE = 'YYYY-MM-DD'
AND (ID IN (LIST_OF_IDS) OR LIST_OF_IDS IS NULL);

Fetching and concatenate two rows value from two different table in SQL

I am unable to Fetch and concatenate two rows value from two different table in SQL.
Please see my query in attached photo.
Following query doesn't providing me the exact data
SELECT RequestNo+'::'+convert(varchar(200),(select count(RID)+1
from BDProjectProposal
Group by RID)) AS Number
FROM BDRequestorInfo
WHERE (RID = #RID)
Is there any way?
You should use a correlated subquery:
SELECT (RequestNo + '::' +
convert(varchar(200),
(select count(RID) + 1
from BDProjectProposal pp
where pp.RID = ri.RID)
)
)
) AS Number
FROM BDRequestorInfo ri
WHERE ri.RID = #RID;
Can you try below
SELECT RequestNo+'::'+convert(varchar(200),isnull((select count(RID)+1
from BDProjectProposal
Group by RID
having RID = #RID),1) AS Number
FROM BDRequestorInfo
WHERE (RID = #RID)
I only added WHERE clause (having RID = #RID) in Subselect to ensure that there will be only one value returning.
Your subselect returns a dataset causing possibly an SQL error
I modified above query and added ISNULL(....,1) for NULL returns with no rows for a given #RID

Updating a table row multiple values oracle 11g

I m struggling to update one column for a table with a sub query. I have a table where currently one of the values is null.
Currently I have:
UPDATE DW1_PURCHASES SET DW1_PURCHASES.TOTAL_AMT =
(
SELECT DW1_PURCHASES.QUANTITY * DW1_PRODUCTS.PRICE
FROM DW1_PURCHASES, DW1_PRODUCTS
WHERE DW1_PURCHASES.PRODUCT_ID = DW1_PRODUCTS.PRODUCT_ID
)
Although subquery returns data which I need to insert I get a error of single row subquery returns multiple rows.How do I basically shift subquery result to the table?
Thanks.
You don't have to JOINthe update table inside the sub-query. Just correlate the sub-query with update table
UPDATE DW1_PURCHASES
SET DW1_PURCHASES.TOTAL_AMT =
(
SELECT DW1_PURCHASES.QUANTITY * DW1_PRODUCTS.PRICE
FROM DW1_PRODUCTS
WHERE DW1_PURCHASES.PRODUCT_ID = DW1_PRODUCTS.PRODUCT_ID
)
Note : If your DW1_PRODUCTS table has duplicated PRODUCT_ID then even now there is a possibility to get the same error

The result of a scalar fullselect, SELECT INTO statement, or VALUES INTO statement is more than one row

I have a problem about my query and i dont know what to do about it.Here is my query.and error i take.
select prd.product_id,prd.prd_name ,prd.prd_longname ,prd.prd_brand ,prd.prd_picture ,prd.market_comment ,prd.categ ,prd.status_id ,prd.status ,prd.active_stock ,prd.slot_date ,prd.currency ,prd.selling_price ,prd.old_price ,prd.type_of_sell ,prd.catalog_id ,prd.catalog_name ,prd.demo ,prd.demo_id,
(select coalesce(count(prd_attribute_id),0) from PRD_ATTRIBUTE where status_id = 1 and product_id = prd.product_id and batch_code <> '0000') as ATTR_CNT ,
(select prd_attribute_id from PRD_ATTRIBUTE where product_id = prd.product_id and batch_code = '0000' and status_id = 1),
(select categ_url from DBNAME.PRD_CATEGORY
where parameter_id = prd.categ_id)||'/'|| (select prd_url from DBNAME.PRODUCT_URL where product_id = prd.product_id) as CATEG_URL
from TEMP_WEB_PRD prd
order by slotdate desc
fetch first 12 rows only
Error:
[IBM][CLI Driver][DB2/AIX64] SQL0811N The result of a scalar fullselect, SELECT INTO statement, or VALUES INTO statement is more than one row. SQLSTATE=21000
The error message is pretty self-explanatory. One of your sub-selects is returning more than one row back, and the database doesn't know how to handle that. I'm guessing your database is DB2 on Linux/Unix/Windows, based on the error message, so here's the Info Center article on your error.
Yes in short it's due to you are using "=" but duplicate rows returned from sub-select statement.
Suppose you have a simple table:
create table T1 (ID int not null primary key, FID int);
The following statement may return SQL0811N if FID column references the same ID values multiple times.
db2 "select id from T1 where ID=(select fid from T1)"
ID
SQL0811N The result of a scalar fullselect, SELECT INTO statement, or VALUES
INTO statement is more than one row. SQLSTATE=21000
The following statement will run successfully:
db2 "select id from T1 where ID IN (select fid from T1)"
Maybe one of your tables has duplicate data, make sure you've checked it. I have the same problem too, it is caused by duplicate rows and it makes subquery return more than one row.