Home » U++ Library support » U++ SQL » [SOLVED] How to join two tables from two schemas with SqlExp
[SOLVED] How to join two tables from two schemas with SqlExp [message #50841] |
Tue, 08 January 2019 15:06  |
Patisab
Messages: 21 Registered: December 2015 Location: France
|
Promising Member |
|
|
Hello,
I have two schemas (S1 and S2) in one database (D1). I have to join one table from S1 with one table from S2. I am connected to the database whith user who is granted as owner of S1 and as reader of S2. Something like that :
SELECT T1.Col1, T1.Col2, S2.T1.Col2, S2.T1.Col3
FROM T1
INNER JOIN S2.T1 ON S2.T1.Col1 = S1.T1.Col1
When i try to do that with SqlExp like this :
Select(Col1.Of(T1),Col2.Of(T1),Col2.Of(T2),Col3.Of(T2))
.From(T1)
.InnerJoin(S2.T1).As(T2).On(Col1.Of(T2) == Col1.Of(T1))
...i obtain an error message that explains S2 is not declared.
So is it possible? If it is, how?
Thank you very much for your help.
Bests regards... and happy new year
[Updated on: Wed, 09 January 2019 13:24] Report message to a moderator
|
|
|
Re: How to join two tables from two schemas with SqlExp [message #50849 is a reply to message #50841] |
Wed, 09 January 2019 09:22   |
 |
mirek
Messages: 14255 Registered: November 2005
|
Ultimate Member |
|
|
Patisab wrote on Tue, 08 January 2019 15:06So is it possible? If it is, how?
#include <Core/Core.h>
#include <plugin/sqlite3/Sqlite3.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
Sqlite3Session sqlite3;
sqlite3.SetTrace();
SQL = sqlite3;
SqlId T1("T1"), Col1("Col1"), Col2("Col2");
SQLID(T2); SQLID(S2);
SQL * Select(T1(Col1), T1(Col2), T2(Col2), T2(Col2))
.From(T1)
.InnerJoin(S2(T1).As(T2))
.On(T2(Col1) == T1(Col2));
}
produces
select T1.Col1, T1.Col2, T2.Col2, T2.Col2 from T1 inner join S2.T1 T2 on T2.Col1 = T1.Col2
SQLID(T1) and SqlId T1("T1") are equivalent. Also, if you are using .sch files, you can do the same thing by adding '_' to type (like INT_ (Col1) or TABLE_(T1)).
Col1.Of(T1) and T1(Col1) are equivalent (parenthesis form is 'more modern').
You cannot write "S2.T1" - we cannot support that, as C++ does not have "operator." overloading 
Mirek
[Updated on: Wed, 09 January 2019 09:23] Report message to a moderator
|
|
|
|
|
Goto Forum:
Current Time: Fri Apr 25 11:59:49 CEST 2025
Total time taken to generate the page: 0.00509 seconds
|