-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Help translation a sql to criteria
PostPosted: Mon Jan 16, 2012 3:57 pm 
Newbie

Joined: Mon Jan 16, 2012 3:35 pm
Posts: 1
I have the following relationship
Code:
  CREATE TABLE "table4"
   (   "ID" NUMBER(19,0) NOT NULL ENABLE,
    PRIMARY KEY ("ID")
  )


  CREATE TABLE "table1"
   (   "ID" NUMBER(19,0) NOT NULL ENABLE,
   "ID_table4" NUMBER(19,0),
      PRIMARY KEY ("ID")
   )


  CREATE TABLE "table2"
   (   "ID" NUMBER(19,0) NOT NULL ENABLE,
   "BIRTHDAY" DATE NOT NULL ENABLE,
   "ID_table4" NUMBER(19,0),
    PRIMARY KEY ("ID")
   )

  CREATE TABLE "table3"
   (   "ID" NUMBER(19,0) NOT NULL ENABLE,
   "BIRTHDAY" DATE NOT NULL ENABLE,
   "ID_table4" NUMBER(19,0),
    PRIMARY KEY ("ID")
   )


And I'm trying to write the following sql select command in using Criteria Query or Predicate or anything like that(I've tryied everything that i know):
Code:
   select * from table1
                          LEFT JOIN
              (select max(t2.birthday) from table2 t2
              where  birthday < '27-OCT-11' OR birthday = null)
              ON  table1.id_table4 = id_table4
             
              LEFT JOIN
              (select max(t3.birthday) from table3 t3
              where  birthday < '27-OCT-11' OR birthday = null )
              ON table1.id_table4 = id_table4


I have to take all that relationship, but a unique birthday with the rule: the most recent birthday
I've tryied to use Predicates but its bring to me all the birthdays, and I want only the most recent.
Sorry by my english, I hope you understood me.
Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.