Home » U++ Library support » U++ SQL » Sqlite join from select
Sqlite join from select [message #51745] |
Sun, 12 May 2019 16:18  |
coolman
Messages: 119 Registered: April 2006 Location: Czech Republic
|
Experienced Member |
|
|
Hi,
How should I rewrite this SQL command to SqlExp for Sqlite?
SELECT a.*
FROM users a
JOIN (SELECT username, email, COUNT(*)
FROM users
GROUP BY username, email
HAVING count(*) > 1 ) b
ON a.username = b.username
AND a.email = b.email
ORDER BY a.email
This one doesn't work:
Select(a(SqlAll()))
.From(users.As(a))
.InnerJoin(Select(Count(SqlAll()), username, email)
.From(users)
.GroupBy(username, email)
.Having(Count(SqlAll()) > 1)
.AsTable(b))
.On(a(username) = b(username) && a(email) = b(email));
Generated code is:
select a.* from users as a inner join ((select count(*), username, email from users group by username, email having count(*) > 1) as b) on a.username == b.username and a.email == b.email;
But during execution I got `ERROR no such column: b.username ...`
The right command should be (without one bracket before select count(*) and one bracket after b
select a.* from users as a inner join (select count(*), username, email from users group by username, email having count(*) > 1) as b on a.username == b.username and a.email == b.email;
If I rewrite SqlExp to
Select(a(SqlAll()))
.From(users.As(a))
.InnerJoin(Select(Count(SqlAll()), username, email)
.From(users)
.GroupBy(username, email)
.Having(Count(SqlAll()) > 1))
.AsTable(b)
.On(a(username) = b(username) && a(email) = b(email));
It can not be compiled because the error `no member named 'On' in 'Upp::SqlSet'`
Thank you, Radek
|
|
|
|
|
|
|
Goto Forum:
Current Time: Fri Apr 25 12:09:44 CEST 2025
Total time taken to generate the page: 0.00808 seconds
|