Seems I'm rusty at my sql and could use some help.
I'm running into an issue on the search query below:
SELECT COUNT(1) as totalITCount FROM it_table
JOIN i_table on i_table.key = it_table.item_key
WHERE
(key IN (select item_key from it_table where LOWER(it_table.resolution_feild) LIKE ? OR it_table.resolution_field = '' group by item_key) )
and the error coming from the operation is:
nested exception is org.postgresql.util.PSQLException: ERROR: column reference "key" is ambiguous.
I'm not sure what this means. I have another field present in both tables and in that case I "oddly" DON'T see this error. I'd think if anything having a field in two places would make the operation ambiguous, so I'm even more confused.
Thoughts?
Last line references key without specifying table.
(key IN....
should either be
(i_table.key IN....
or
(it_table.key IN....
Related
While executing this code in my project:
Integer countObj = (Integer) ht.findByCriteria(criteria.setProjection(Projections.rowCount())).get(0);
I get the following exception:
com.microsoft.sqlserver.jdbc.SQLServerException: Column "PRODUCT_TASK.PRODUCT_TASK_ID" is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause."
Here I am using two tables.
Product_task with product_task_id as primary key
Product_info with product_info_id as primary key
product_info_id is the foreign key for Product_task.
By executing that query I will get count.
I am getting this SQL query in my logs:
select count(*) as Count from PRODUCT_TASK pt inner join
PRODUCT_INFO pin on pt.PRODUCT_INFO_ID=pin.PRODUCT_INFO_ID
where pin.UPC like ? order by pt.PRODUCT_TASK_ID asc**
I know how to change SQL query (group by clause need to be there) but I don't know how to modify the Hibernate query in order to get the result.
You just need to use Projections's .groupProperty() method in your Criteria.
groupProperty
public static PropertyProjection groupProperty(String propertyName)
A grouping property value
Your code would be like this:
Integer countObj = (Integer) ht.findByCriteria(criteria.setProjection(Projections.rowCount()
.add(Projections.groupProperty("product_task_id"))))
.get(0);
I am running following query:
my query = insert into tbl_name (ID,name, address,...)" +" values (?,?,?)
then I am using query runner class to insert.
myQueryRunnerObj.insert("my query",
result set handler obj,
generated id,
'my name',
'my address',...);
After this I am getting following exception: Exception in thread "main" java.sql.SQLException: ORA-00936: missing expression and sometimes invalid number of arguments expecting 11 given 10
What could be the reason to get this exception?
Correct syntax is:
INSERT INTO dept (deptno, dname) VALUES (dept_seq.nextval, 1);
or
INSERT INTO dept (deptno, dname)
SELECT dept_seq.nextval, 2
FROM dual;
ORA-00936: missing expression
Cause: A required part of a clause or expression has been omitted. For example, a SELECT statement may have been entered without a list of columns or expressions or with an incomplete expression. This message is also issued in cases where a reserved word is misused, as in SELECT TABLE.
Action: Check the statement syntax and specify the missing component.
check this
While running the below query to get the latest message with the latest data using the createdOn column
i get the below error
select count(m) from MessageWorkFlowStatus mwfs1 where mwfs1.createdOn =(select max(createdOn) from MessageWorkFlowStatus mwfs2 where mwfs1.status= 'NEW' or mwfs1.status='IN PROGRESS')
The encapsulated expression is not a valid expression
Please let me know if i can run Query this way
First of all, count(m) is not correct. It should either be count(*) or count(mwfs1). Secondly, in your inner query, you are using status column from the outer query table (mswfs1) which is logically wrong. It should instead be mwfs2.status = 'NEW' or mwfs2.status = 'IN PROGRESS'.
I think your query should be:
select count(mwfs1)
from MessageWorkFlowStatus mwfs1
where mwfs1.createdOn = (
select max(createdOn)
from MessageWorkFlowStatus mwfs2
where mwfs2.status= 'NEW' or mwfs2.status='IN PROGRESS')
Hi I'm executing this query in my java code and it tells me
org.postgresql.util.PSQLException: ERROR: column "st_srid" does not exist
However when I run it directly in pgAdmin it shows me the column and the value inside.
Here is my query:
"Select Distinct ST_SRID(shape) from TableName where shape IN (SELECT shape from TableName)"
I appreciate any help
Distinct needs parenthesis around the st_srid function call.
I'm using JDBC to connect to the Oracle database and ask how many methods are in the String class. I keep getting the following error:
Exception in thread "main" java.sql.SQLSyntaxErrorException: ORA-00936: missing expression
at the following line:
ResultSet res1 = stmt.executeQuery("SELECT (Distinct method_name) FROM all_java_method WHERE name LIKE 'String' Order BY method_name");
I don't have a ton of experience with SQL yet so any help would be appreciated.
Thanks.
Substitute (Distinct method_name) with Distinct method_name because that is the correct syntax for the SELECT
Also, you need to substitute 'String' with 'String%' or '%String%' (depends on what exactly are you wanna fetch, I don't know java, so...), otherwise it is logicaly become equal to name = 'String'