connect to multiple ms access databases using odbc - ms-access

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

Related

Querying using multiple databases (connections) in dbeaver

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.

Select in select statement (Join Table) SQL

What select statement I should use to get the result as below:
Currently when i run my stored procedure below, it will display the "Result" image:
select vm.ID_Vendor,vm.Vendor_Name,vpe.Company_Name,vpe.TOTAL,
vpe.COUNT,vpe.AVERAGE from VENDOR_MASTER vm
LEFT JOIN
(select vvd.ID_Vendor,sc.ID_Company,sc.Company_Name,vvd.VPE_Average_Score,
SUM(vvd.VPE_Average_Score) AS TOTAL,COUNT(vvd.VPE_Total_Score) AS COUNT,
(SUM(vvd.VPE_Average_Score)/COUNT(vvd.VPE_Total_Score)) AS AVERAGE,
vvm.Assessor_Name FROM VENDOR_VPE_MASTER vvm
left join VENDOR_VPE_DETAIL vvd on vvm.ID_VPE_Master=vvd.ID_VPE_Master
left join SETUP_COMPANY sc on vvm.ID_Company=sc.ID_Company
left join REF_EVL_RATING rer1 on vvd.Quality_Product=rer1.ID_Evl_Rating
left join REF_EVL_RATING rer2 on vvd.Service=rer2.ID_Evl_Rating
left join REF_EVL_RATING rer3 on vvd.Technical=rer3.ID_Evl_Rating
left join REF_EVL_RATING rer4 on vvd.Quality_Mgmt=rer4.ID_Evl_Rating
left join REF_EVL_RATING rer5 on vvd.Price=rer5.ID_Evl_Rating
GROUP BY vvd.ID_Vendor,sc.ID_Company,sc.Company_Name,vvd.VPE_Average_Score,
vvd.VPE_Average_Score,vvd.VPE_Total_Score,vvm.Assessor_Name) as vpe on vm.ID_Vendor=vpe.ID_Vendor
order by vpe.ID_Vendor
EDIT: It seems now that you want to change your GROUP By clause, see my comment below
This is not possible as the SQL Server Management Studio is about the data and server management, it's not made to create reports or export well-formatted data (as said in the comments). However, if you have Excel installed, you can execute the query from Excel (Data -> Get External Data). This allows you to format the headers as you want and it is easier to export to other formats (PDF, images, ...).
As an alternative, you could use Reporting Services where you have a lot of possibilities for these things. However, the Excel solution will be easier to implement if you only need vertical headers.

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

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.

Query: Tables with indexing/foregeing keys/correlated data

I am currently working with a MySQL database table structure. I found a great table structure online but i am not sure how to duplicate such thing. I am new to this and I am requesting help in creating a query that will create all tables( which have correlated data(index), foreign keys, many to many relationships, etc.).
Random I was able to make a query to select all fields:
SELECT *
FROM schedule
INNER JOIN semester
ON schedule.semester_id = semester.id
INNER JOIN office_hours
ON office_hours.schedule_id = schedule.semester_id
INNER JOIN faculty
ON faculty.id = office_hours.faculty_id
INNER JOIN faculty_titles
ON faculty_titles.faculty_id = faculty.id
INNER JOIN faculty_education
ON faculty_education.faculty_id = faculty.id
INNER JOIN section
ON section.faculty_id = faculty.id
INNER JOIN class
ON class.id = section.class_id
INNER JOIN major_class_br
You find a good documentation of how to create tables in the corresponding MySQL documentation:
MySQL 5.0
MySQL 5.1
MySQL 5.5
You can user MySQL Workbench if you want to play a little with a graphical front-end. You can download it from the link or install it from you Linux repository.
There are three section in the workbench: SQL Development, Data Modeling, and Server Administration. Choose "Create new EER Model" in the Data Modeling section and then "Add Diagramm". You can insert new Tables by drag and drop from the left bar and apply your model to your database by clicking on the Database menu entry and then "Forward Engineer...".
The table structure you linked in you querstion was created by MySQL Workbench as well. Therefore, it should be easy for you to compare it.