• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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

 
Ranch Hand
Posts: 600
  • 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: 39996
807
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: 600
  • 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: 39996
807
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: 600
  • 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.
 
Evildoers! Eat my justice! And this tiny ad's justice too!
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic