Querying using multiple databases (connections) in dbeaver - multiple-databases

I want to access multiple databases(multiple connections) at once in dbeaver and to the SQL querying.
As an example, I have 3 data connections: A, B and C.
I want to run a query like this:
select * from A
left join B on A.column=B.column
left join C on A.column=C.column
Is this not allowed in dbeaver?

No. You need a Data Virtualization or Data Integration tool.

Related

connect to multiple ms access databases using odbc

When creating applications in MSAccess (VBA) you can connect to multiple databases (mdb files) by simply creating links to them. Now I have rewritten the user interface in C/C++ and using ODBC to connect to the database. How can I connect to a second database (mdb file) and joining data from tables from one database to the other. For instance database 1 (file1.mdb) contains a table invoice and database 2 (file2.mdb) contains a table prices. How can I join invoice with prices?
Assuming both databases reside on same network/server or machine, consider distributed queries where you qualify file names in brackets which is allowable with the Jet/ACE SQL engine.
SELECT p.*, i.*
FROM [C:\Path\To\File1.mdb].[Prices] p
INNER JOIN [C:\Path\To\File2.mdb].[Invoices] i
ON p.ID = i.PriceID
You can even connect to Excel workbooks, assuming data is in tabular format starting in A1 cell with column headers:
SELECT p.*, e.*
FROM [C:\Path\To\File1.mdb].[Prices] p
INNER JOIN [Excel 12.0 Xml;HDR=Yes;Database=C:\Path\Workbook.xlsx].[SheetName$] AS e
ON p.ID = e.PriceID
And same with CSV files:
SELECT p.*, c.*
FROM [C:\Path\To\File1.mdb].[Prices] p
INNER JOIN [text;database=C:\Path\To\CSV\Folder].CSVFile.csv AS c;
ON p.ID = c.PriceID

How to join two tables in different databases in Workbench

How does one join two tables that are in different databases using the SQL runner in MySQL Workbench?
I have searched for this and explored the interface but could not a find a solution.
If it is not possible with Workbench, is it possible with another client?
Note: the databases exist under different connections and ports!
You can simply join the table of different database. You need to specify the database name in your FROM clause. To make it shorter, add an ALIAS on it,
SELECT a.*, -- this will display all columns of dba.`UserName`
b.`Message`
FROM dba.`UserName` a -- or LEFT JOIN to show all rows whether it exists or not
INNER JOIN dbB.`PrivateMessage` b
ON a.`username` = b.`username`
So just adding DB name before tablename will solve your problem.
In that Case you can use,FEDERATED Storage Engine to join two mysql connections running on two servers.Please refer doc to know more about it
http://dev.mysql.com/doc/refman/5.0/en/federated-storage-engine.html

SQL join on different versions of table

I have multiple suppliers of data, which I will call A, B, & C. A has a database that is updated monthly. B & C (my application actually gets more than 2 other data suppliers, and there are over 100) reference a table in A and tell which month from A they are using. A may update, add or delete records for each monthly release. Most of the records from A will stay the same. I currently use multiple databases, and specify the database to use in each join.
What is a good way to store the data from A so that B & C joins to the data will work efficiently? Does NoSQL or ORDBMS solve this issue?
If ...
you're using MySQL and
your user id has appropriate privileges and
your databases all live on a single server
you can use tables from multiple databases quite easily, just by qualifying the table names in your queries. For example, this sort of thing performs very well.
SELECT a.id, b.vendor
FROM A.stock a
JOIN B.shipments b ON a.sku = b.sku

If there a way I can inner join a MS Sql table to a MySql Table in one query using MySql?

I have 2 servers one servers runs Microsoft SQL Server and the other one is using MySql.
I need to be able to inner join a table from MS SQL name it "A" to a table "B" located on a different server that uses MySql
So I want to be able to do something like this
SELECT A.*, B.* FROM A INNER JOIN B ON A.id=B.id LIMIT 100
How can I do this? note that both servers are on the same network.
1st link on google states...
you need to install this:
http://www.mysql.com/products/connector/
and follow this guide:
http://technikhil.wordpress.com/2007/05/13/getting-microsoft-sql-server-and-mysql-to-talk/
to link up the servers and then use openquery to execute MS SQL queries.

inner join in mysql (to-many connections)

SELECT
a.cdrID as cdrID,
a.userName as userName,
a.callingStationID as callingStationID,
a.orgClientAccountID as orgClientAccountID,
a.terClientAccountID as terClientAccountID,
a.calledStationID as calledStationID,
a.setupTime as setupTime,
a.connectTime as connectTime,
a.disconnectTime as disconnectTime,
a.orgDestCode as orgDestCode,
a.orgBilledDuration as orgBilledDuration,
a.orgBilledAmount as orgBilledAmount,
a.terDestCode as terDestCode,
a.terBilledDuration as terBilledDuration,
a.terBilledAmount as terBilledAmount,
a.orgRateID as orgRateID,
a.terRateID as terRateID,
b.dtDestName as orgDestName,
c.dtDestName as terDestName,
d.clCustomerID as terClientName,
1 as cdrwsid,
cast((e.crFlatRate*a.orgBilledAmount)as decimal(10,4)) as cdrsale,
cast((f.crFlatRate*a.terBilledAmount)as decimal(10,4)) as cdrpurchase,
cast(((e.crFlatRate*a.orgBilledAmount)-(f.crFlatRate*a.terBilledAmount))as decimal(10,4)) as cdrprofit
FROM Successful.vbSuccessfulCDR_508 a
inner join iTelBilling.vbDestination b on a.orgDestCode=b.dtDestCode
inner join iTelBilling.vbDestination c on a.terDestCode=c.dtDestCode
inner join iTelBilling.vbClient d on a.terClientAccountID=d.clAccountID
inner join iTelBilling.vbCallRate e on a.orgRateID=e.crCallRateID
inner join iTelBilling.vbCallRate f on a.terRateID=f.crCallRateID
where setupTime between '1317761709564' and '1317804909564' and a.terBilledDuration!=0
I have problem with this query some time this query runs fine some time it got hanged on server and some time it through error to-many connections. Can any one tell me what to do.
The problem sounds like this query is running very long; This can be due to the fact, that you need to have a look at the indexes that the query uses. To get an overview (and perhaps optimize your indexes and pks) use the command:
> EXPLAIN SELECT
a.cdrID as cdrID,
a.userName as userName,
...
Another reason can be, that there are deadlock-situations or situations, where the query is running very long since a table is locked. If this happens, other users that execute that query (I assume you are using it in an webserver-context) are building up a "waiting row". Each user that executes this query (which is waiting) needs a connection of its own. If this happens, your server is running out of concurrent connections in a short time.
This can be solved in two ways:
1) Make sure your query has more performance (check the pks and indexes)
2) Increase your concurrent connections settings in your SQL-server:
This can be done by setting the following value to 200 connections (for example) in your my.cnf
max_connections = 200
3) Optimize your mySQL. Make sure your querycache, key-buffer, ... are set to a fitting value. Further informations on mySQL-Performance tuning you will find here.
It might be that the engine is trying to use your SMALLER lookup tables for performing the join instead of your PRIMARY table of CRD (Call Data Records), like phone system billing. You are trying to get proper origination / destination billing codes and rates. Sometimes MySQL will try to think for you by using the smaller tables first.
Ensure you have an index on your Successful table on the "setupTime". In addition, add "STRAIGHT_JOIN" clause to the top
SELECT STRAIGHT_JOIN ... rest of query.
This tells MySQL to process based on the tables you have ordered in that order. It appears the joins to your destination, client and call rate tables WOULD have the corresponding index on their join keys respectively... if not create them.