Join Two Different Database

junaidahmed

Well-Known Member
Licensed User
Longtime User
How to Join Two Different Database Table in SQLite,For Example

Select Code,Amount from Account ---> Database1

Select Code,Amount from Account ---> Database2

Pls advise
 

Merlot2309

Active Member
Licensed User
Longtime User
Hello,

To use data in/from different tables you have 1 joint value/field in each table.
What I use is more or less the following:

Dim a Variable in the Process Globals (e.g. Name)
so I can use the value in other forms and then I get the value of this variable
like this:

B4X:
crInfo = [I]SQLDatabaseName[/I].ExecQuery2("Select * FROM [I]Tablename[/I] WHERE Name = ?", Array As String([I]Variable[/I])).

The same goes for deleting and updating records.

Regards,
Helen.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Sure. You can declare two sql objects for each database, perform your queries, and if needed insert data from one database to the other.
 
  • Like
Reactions: eps
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
Yes it can be done. You can use the the ATTACH DATABASE command to attach
one database to another.


B4X:
DIM oSQL AS SQL
oSql.Initialize(File.DirRootExternal & "/databases","database1.db",False)
cSQLAttach = "ATTACH DATABASE " & File.DirRootExternal & "/dasbases/" & "database2.db"   & " AS db2"
oSql.ExcNonQuery(cSQLAttach)


This would mean you could join tables from database1 to database2 in one SQL query. So in your case you could do.

"SELECT Account.CODE, Account.Amount, DB2.Account.code "code2", DB2.Account.Amount "amount2" FROM Account, DB2.Account WHERE Account.CODE = DB2.Account.CODE
 
Last edited:
Upvote 0

Itila Tumer

Active Member
Licensed User
Longtime User
I have a persons db, and have person table too. I have TabHost of three . ı want to see different tables in each page. What do you recommend me ?
 
Upvote 0
Top