JOIN tables from different databases (same server) - c14 |
Hi all,
Using Ci4, I have a need to run a query on two tables in different databases (table1 on db1, table2 on db2). I have 2 connections configured & working fine for everything else in //Config/Database (con1, con2). I need to run a query something like this, where connection (con1) connects to db1: PHP Code: public function getEmpsPlusUsers () { But of couse this throws a error as I do NOT have permission to access db2 becuase I have NOT established a connection!! Any ideas anyone ???
You must have an account with the privilege to grant privileges to other users. See the documentation for your DBMS for details.
All manipulations with users are performed through SQL queries.
(07-11-2022, 06:23 PM)iRedds Wrote: You must have an account with the privilege to grant privileges to other users. See the documentation for your DBMS for details. Thank you so much, it works like a dream :-) The day I spent trying to get this to work wasn't wasted though, as I learnt quite a bit trying all sorts of things in Ci4. Again, many thanks.
To build a server link, use the sp_addlinkedserver function. For further information, consult the reference documentation. After you've created the server link, you'll write the query normally, merely prefixing the database name with the other server's name. I.E:
Code: -- FROM DB1 Once the connection is established, you can use OPENQUERY to execute a SQL query on the remote server and return just the data. This is somewhat quicker, as it allows the remote server to optimize your query. In the example above, if you store the data in a temporary (or in-memory) table on DB1, you'll be able to query it just like joining a conventional database or data independence used in DBMS. For example: Code: -- Fetch data from the other database server |
Welcome Guest, Not a member yet? Register Sign In |