I have two tables table 1 and table 2. Both have same name id column.
As it's a left outer join query, I have to use aliases.
In sortKeys, If I mention id , error is
Caused by: org.postgresql.util.PSQLException: ERROR: column reference "id" is ambiguous
In sortKeys, If I mention t1.id , error is
Caused by: org.postgresql.util.PSQLException: The column name t1.id was not found in this ResultSet.
How to handle such queries?
I am using latest spring boot version 2.2.5.RELEASE
I have seen other posts related to this issue on stackoverflow. However, those are in older versions of spring batch and hence I should not face this issue.
One way you could solve this issue, is by adding the t1.id as projection and naming it something else, like :
select t1.id as id_t1 ....
and in your sortKeys add "id_t1".
Hope this helps
The answer by #youness.bout and another kind programmer worked for me. I've documented it here https://github.com/spring-projects/spring-batch/issues/1208#issuecomment-994234546. It appears to be a known issue in Spring Batch project.
Rewriting the answer here:
Using the same column name alias as that in column name in the select clause - t1.table1_column1 as 't1.table1_column1'
Enclosing the column name alias in single quote (') in the select clause - t1.table1_column1 as 't1.table1_column1'
Used the column name alias as the sort key - setSortKey("t1.table1_column1")
Here's what I did in kotlin
#Bean
#StepScope
fun readQueryProvider() = SqlPagingQueryProviderFactoryBean().apply {
setDataSource(dataSource)
setSelectClause("select t1.table1_column1 as 't1.table1_column1', t1.table1_column2,"
+ " t1.table1_column3, t2.table2_column2, t3.table3_column3")
setFromClause("table1 t1"
+ " inner join table2 t2 on t1.table1_column1 = t2.table2_column1"
+ " inner join table3 t3 on t2.table2_column2 = t3.table3_column2"
+ " inner join table4 t4 on t1.table1_column1 = t4.table4_column1")
setWhereClause("where t3.table3_column2 = :placeholder1"
+ " and t2.table2_column3 = :placeholder2 and t4.table4_column2 = :placeholder3")
setSortKey("t1.table1_column1")
}
Related
I am a complete beginner to BigQuery, and I am trying to create an inner join between two table names, where the column 'title' is the joining column. I believe my syntax is correct, but I do not know what I am doing wrong when I input the ON clause. Here is my syntax:
SELECT
*
FROM
book-to-film-adaptations.movies.movies_metadata_relevant
JOIN
book-to-film-adaptations.goodreads_books.goodreads_books_relevant_data
ON
movies_metadata_relevant.title = goodreads_books_relevant_data.title
I get this error message: Unrecognized name: movies_metadata_relevant at [8:3]
I have tried it with the full names (book-to-film-adaptations.movies.movies_metadata_relevant), but then I get an error message: "Syntax error: Unexpected keyword TO"
Any suggestions?
Thanks
You need to alias tables and use those like in below example - but in this case you will need
...
...
FROM
`book-to-film-adaptations.movies.movies_metadata_relevant` t1
JOIN
`book-to-film-adaptations.goodreads_books.goodreads_books_relevant_data` t2
ON
t1.title = t2.title
or if join columns have same name (like in your case) you can use below version
...
...
FROM
`book-to-film-adaptations.movies.movies_metadata_relevant` t1
JOIN
`book-to-film-adaptations.goodreads_books.goodreads_books_relevant_data` t2
USING (title)
I have two table which I want to select Name from t2.
The situation is following.
I have t1 Policy which containt EmployeeID
And table t2 which containt Name
Now I want to select which Employee release policy.
So in t1(Policy- AUTO.POL) I have column: SIFRA_RAD
and t2(Employee-AUTO.SIFRAD) I have colum: SIFRA_R, Ime
I try something like this:
select auto.pol.sifra_rad, auto.sifrad.ime
from auto.sifrad
inner join auto.pol on auto.sifrad.ime = auto.pol.sifra_rad;
After that I get error
ORA-00933: SQL command not properly ended
I have no idea what is wrong here. Any suggestion?
The problem comes from query, and we fix it
select p.sifra_rad, s.ime from auto.sifrad s, auto.pol p where s.ime = p.sifra_rad
post_code is a primary key in the location table and foreign key in job. I am trying to join them, could anyone help.
SELECT job.start_date, job.cust_id, job.veh_id, location.post_code, location.country_name_location
FROM job
INNER JOIN location job.post_code ON location.post_code AND country_name_location = 'France';
SQL Error: ORA-00905: missing keyword
00905. 00000 - "missing keyword"
*Cause:
*Action:
Your ON is in the wrong position:
SELECT job.start_date, job.cust_id, job.veh_id, location.post_code, location.country_name_location
FROM job
INNER JOIN location ON job.post_code = location.post_code AND country_name_location = 'France';
There is an error in your syntax. The ON keyword is meant to come after you specify the table you are joining with. So the correct query would be:
SELECT job.start_date, job.cust_id, job.veh_id, location.post_code, location.country_name_location
FROM job
INNER JOIN location ON job.post_code = location.post_code AND country_name_location = 'France';
I got the below error in hive while I am executing the hql like this.
Select a.col,b.col from tab a left join tab b on a.id =b.id and a.code in
(Select c.code from tab c where c.id=123 and c.dec='123a');
Note: c.id is pk and c.dec is unique id
Error: semantic in exception 0 children returned.
Can any one help to resolve the above issue.
I think this is happening because you are using a MySQL reserved keyword "desc" as your column name. So you can change it and try again.
You can refer to this link for the list of all the reserved keywords for MySQL :https://dev.mysql.com/doc/refman/5.5/en/keywords.html
I'm practically new in using oracle and I bumped into a blocker. Below is the query that I created based on what I have researched online to update multiple columns of a table with values from a nested join statement.
UPDATE
(
SELECT
A.COLUMN1 OLD_COLUMN1,
BC.COLUMN1 NEW_COLUMN1,
A.BALANCE OLD_COLUMN2,
BC.COLUMN2_MIN NEW_COLUMN2,
A.COLUMN3 OLD_COLUMN3,
BC.COLUMN3 NEW_COLUMN3
FROM TABLE_A A
INNER JOIN
(
SELECT B.TWWID,
B.ITEMDATE,
B.COLUMN2_MIN,
C.COLUMN3,
C.COUNTRYID,
C.COLUMN1
FROM TABLE_B B
LEFT OUTER JOIN TABLE_C C
ON TO_CHAR(B.ID) = TO_CHAR(C.ID)
) BC
ON A.ID = BC.ID
AND A.DATE = BC.DATE
)ABCUPDATE
SET ABCUPDATE.OLD_COLUMN1 = ABCUPDATE.NEW_COLUMN1,
ABCUPDATE.OLD_COLUMN2 = ABCUPDATE.NEW_COLUMN2,
ABCUPDATE.OLD_COLUMN3 = ABCUPDATE.NEW_COLUMN3;
Selecting the sub-query returns the expected results but when I run the update script as a whole an error is returned.
ORA-01779: cannot modify a column which maps to a non key-preserved
table
Can anyone please explain why I encounter this error and what adjustments can I do to the script to make it work?
Thanks in advance!