• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41878
909
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic