Hallo Michael,
I'm not sure but i'll try
Criteria criteria = new Criteria();
// create aliases
criteria.addAlias("t1", TablePeer.TABLE_NAME);
criteria.addAlias("t2", TablePeer.TABLE_NAME);
// add what we want to select
criteria.addSelectColumn(TablePeer.SOMETHING);
// where clause
criteria.addJoin("t1.id", "t2.id");
criteria.add("t1.value", (Object)"somevalue");
criteria.add("t2.value", (Object)"somevalue");you can write instead "t1.value" more sophisticated solution like String alias1 = "t1"; criteria.add(alias1 + "." + extractColumnName(TablePeer.VALUE), (Object)"somevalue");
Regards, Kostya
Michael Burschik wrote:
Now, you might think I don't really need the alias feature, but that is because I made a slight mistake in my example. What I actually need to do is this:
select t1.something from TABLE as t1, TABLE as t2 where t1.id=t2.id and t1.value=somevalue and t2.value=someothervalue
You see, I use the same table more than once in order to avoid sub-selects.
Since I wasn't able to figure out a way to do this with Criteria, I tried to do without by piecing together an SQL statement and using the Torque connection to submit it to the database. Strangely enough, the select took very long to complete (something like three minutes) and the result was not correct, although the same statement typed at the command prompt (mysql) was blindingly fast and delivered the correct results. Can anyone suggest a reason for this behaviour?
Regards
Michael Burschik
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
