Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

how to set PreparedStatement if the select query contains id of 1st table = id of 2nd table ?

 
Ranch Hand
Posts: 559
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to seek advice on a query "

Select t1.a, t2.b, t2.c from t1 join t2 on t1.id = t2.id where t1.a = ?, t2.b = ?, t2.c = ?

My questions :

1) if I do not know the id, should I put a ? in the query
2) do I need to set prepared statement for id ?

Thanks in advance.
 
author & internet detective
Posts: 39540
778
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't care what the id is, you don't need a ?. It's only if you want t a specific value.

The ? you have for the other values are good.
 
tangara goh
Ranch Hand
Posts: 559
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:If you don't care what the id is, you don't need a ?. It's only if you want t a specific value.

The ? you have for the other values are good.



Thanks Jeanne.

BTW, is it possible to add group by id at the end and it will make the data less duplicated ?
 
Jeanne Boyarsky
author & internet detective
Posts: 39540
778
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding group by won't help because then you'd have to use an aggregate. If you are worried about duplication, add a distinct to your select clause. I don't know how much duplication you'd have though. Id sounds pretty unique.
 
tangara goh
Ranch Hand
Posts: 559
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:Adding group by won't help because then you'd have to use an aggregate. If you are worried about duplication, add a distinct to your select clause. I don't know how much duplication you'd have though. Id sounds pretty unique.



Hi Jeanne,

It is not adding Select distinct on t1.1a right ?

Select t1.a, t2.b, t2.c from t1 join t2 on t1.id = t2.id where t1.a = ?, t2.b = ?, t2.c = ?

I have use distinct on t1.id = t2.id but then it gives me error...

so, I am not sure where about to put Select distinct.

Could you kindly let me know ?

Tks.
 
I wish to win the lottery. I wish for a lovely piece of pie. And I wish for a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!