Hi Lukas:
Thanks for helping me out with this. I certainly appreciate it! It worked
like a charm. Here's the final method:
public void testUnion(DSLContext context) {
// "SELECT CONCAT(last_name,', ',first_name,' (home)') AS name,home_email
FROM attendees WHERE list = 1 UNION SELECT CONCAT(last_name,', ',first_name,'
(work)') AS name,work_email FROM attendees WHERE list = 1";
Result<Record2<String,String>> result = context.select(
concat(ATTENDEES.LAST_NAME,inline(",
"),ATTENDEES.FIRST_NAME,inline(" (home)")).as("name"),ATTENDEES.HOME_EMAIL)
.from(ATTENDEES)
.where(ATTENDEES.LIST.eq(Boolean.TRUE))
.orderBy(ATTENDEES.LAST_NAME)
.union(select(concat(ATTENDEES.LAST_NAME,inline(",
"),ATTENDEES.FIRST_NAME,inline(" (work)")).as("name"),ATTENDEES.WORK_EMAIL)
.from(ATTENDEES)
.where(ATTENDEES.LIST.eq(Boolean.TRUE)).orderBy(ATTENDEES.LAST_NAME))
.fetch();
for(Record2<String,String> record : result) {
String name = record.value1();
String email = record.value2();
if(email != null) {
System.out.println("\"" + name + "\"" + " <" + email + ">");
}
}
}
And the output is:
...
"Redlich, Michael (home)" <[email protected]>
...
On Sunday, November 26, 2017 at 8:47:17 PM UTC-5, Michael Redlich wrote:
>
> Hello:
>
> I'm still new to jOOQ. I'm trying to duplicate the following SQL
> statement:
>
> String sql = "SELECT CONCAT(last_name,', ',first_name,' (home)') AS
> name,home_email FROM attendees WHERE list = 1 UNION SELECT
> CONCAT(last_name,', ',first_name,' (work)') AS name,work_email FROM attendees
> WHERE list = 1";
>
> I've tried the *.union()* method in conjunction with *.selectFrom()* and with
> *.select()* methods and still getting errors relative to types, etc..
>
> I would appreciate any help...thanks!
>
> Mike.
>
>
--
You received this message because you are subscribed to the Google Groups "jOOQ
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.