How to get a table from two databases? - ms-access

Using Access 2003
I want to get a table value from the two databases
Database – 1
Emp_Table
Database – 2
Customer_Table
Select * from Database-1.Emp_Table, Database-2.Customer_Table
The above query is showing error in the Access. I tried a Join query also, it showing error.
Can any one to solve this problem?
Need Query Help.

Try using square brackets -
SELECT * FROM [Database-1].[Emp_Table], [Database-2].[Customer_Table]
Or, try this.

First, assuming the query is running in Database 1, you will need to create a "linked table" to link to Database 2's table in Database 1.
Once you do that, you can write it simply as:
Select * from Emp_Table, Customer_Table
Since you are "in" database 1, you won't have to qualify Emp_Table, and since you have Database 2's Customer_Table linked in, you won't have to qualify it either.

I don't have Access 2003, but in Access 2007 you can do this:
Click on the "External Data" tab.
Click on the "Access" icon.
Choose the location of your second Access database.
Select "Link to a data source by creating a linked table".
This should add the tables in your second database linked in your original one. You can then write queries to query data from either one or both like you normally would. I'm sure the same functionality is available in Access 2003, just a slighty different visual route to achieve the same thing.

Is there some relationship between the tables, or do you want just a dump of the whole table? Also, post the join you tried and the error you got, it would help in the troubleshooting...
If you want all records from both tables, you would need to use a UNION query like this:
Select * from Database-1.Emp_Table;
UNION Select * from Database-2.Customer_Table;
This assumes that there are the same number of columns in both tables. If not change the * to the specific columns you want to list from each table.

Related

In Access, how can I compare a truncated division with the real division on linked table in SQL server

My Access 2010 database has a linked table (on a SQL Server 2012 backend), containing fields ID, Qty, PackSize. My query is meant to select records where Qty is not a multiple of the packsize. Normally I achieve this with a where clause like so: "Where Qty/Packsize <> Fix(Qty/Packsize), but although this works on local tables or linked tables that live in other Access databases, on linked tables which live in SQL server, it returns no results.
If I split up the query into two parts, one with no where clause, creating a new table with ColA: Qty/Packsize, ColB: Fix(Qty/PackSize), and then select where ColA <> ColB, it works fine.
Since I don't really care what the values are, just to know whether they're different, I also tried Int() instead of Fix.
Even weirder, "Where Cdbl(Qty/Packsize) = int(Qty/Packsize)" returns all the records, despite showing me that Cdbl(Qty/Packsize) is for example 425.5 and int(Qty/Packsize) is 425.
Any idea what's going on or how I can achieve this another way? It needs to be in a single step though, as it's really the basis for a record selection in VBA. Why would it not work over a SQL linked table? I've tried in separate databases as well and using a different SQL table, in case it was merely a glitch.
Many thanks in advance.
(Also the title of this question is awful. Edits gratefully received.)
It could be a floating point issue, so try with integers only:
Where Qty <> Fix(Qty/Packsize) * Packsize
By the way, Fix and Int behave the same for positive values.

Connect Tables in MySQL

I'm attempting to connect two tables in MySQL so that when selected, a value is pulled from the table.
Table 1
id
mobile_car
Table 2
id
mobile_car
car_domain
When the mobile_car is selected via a dropdown and the user registers this, I would like to be able to have it connect to the car_domain so I can call this later in the application.
For example, if the user selects "Verizon" as their mobile_car, I would like it to link to the car_domain "#vtext.com" so I can connect their phone number with the car_domain. Essentially, I'm sending a text by way of emailing their cell number.
I know there are programs and pre-built options, but I'd like an understanding of how this could be done.
Thanks!
Try joining your two tables together:
SELECT t1.mobile_car, t2.car_domain
FROM Table1 t1 INNER JOIN Table2 t2
ON t1.mobile_car = t2.mobile_car
I'm also assuming that your actual table structure will be more complex than this, since right now you can actually just query Table 2 by itself to get what you need.

How to "inner join" two website DB's

I have a requirement and would like to know the best way of achieving the goal.
The idea is to "inner join" two tables from two databases from two completely different websites.
For example, I have a website that tables ID's from another source. I then want to analyse those ID's in more detail by joining my table with the other websites table.
My initial thought would be to pass a JSON list of ID's from my table to a php file on the 3rd party host, which would then do a "select fields from table where id in (JSONList)", then pass back the information of which I would then stitch together and display.
Is there a better / easier way of doing this?
You can do it directly in the database, which allows you to use sql.
MySql will allow you to create a Federated Table locally, that when accessed will pull the data automatically from the remote database.
Once you've got your federated table setup you should be able to write your join normally e.g:
select * from table1 inner join table2 on table1.joinkey = table2.joinkey;
There are a number of related questions already if this is the approach you wish to take (or at least try):
MySQL: SELECT from another server
I need to join table from other database and sometimes other server
https://dba.stackexchange.com/questions/81411/select-in-federated-table-is-to-slow
Unfortunately the docs say this will only currently work for mysql to mysql: http://dev.mysql.com/doc/refman/5.1/en/federated-create-connection.html

Temporary data type casting for a single Query

Alright, I realize that what I am about to ask may not be possible, which I can live with. But If it is possible it will make my life a lot easier.
Within my MS Access Database, I am attempting to query 2 tables. These tables are both linked to my Access DB, one is linked to an Excel file (MSSB Reps DTP) containing a dump from a seperate DB2 database.
The other table in my query (SalesPage DNK Rep Query) is linked to another Access DB, which is in turn linked to a SQL databse. Here is an image of the Query design screen:
Where the tables are linked is not so much important as the fact that since they are linked tables, and since this is MS Access, I can not edit the tables. Therefore, I can not simply pop into design mode of either table and change the data type of a given column.
Each table has a column named CRD Number. I want to create an inner join between these two tables based on this column. Just a simple, everyday, inner join. I can not however, because the CRD Number column is stored as a Number for the MSSB Reps DTP table, and as text in the SalesPage DNK Rep Query table.
I was wondering if there is some way to temporarily use a fucntion to "cast" the CRD Number column fromo the MSSB Reps DTP table as text, so that I can run this query. However, any solution will be appreciated. Just don't tell me to edit the Excel document. I am trying very hard to avoid that for various reasons.
You can use CStr to cast the number as text.
SELECT *
FROM
[MSSB Reps DTP] AS m
INNER JOIN [SalesPage DNK Rep Query] AS s
ON CStr(m.[CRD Number]) = s.[CRD Number];
The Access query designer may refuse to display that join in Design View, but you can switch to SQL View and edit the statement text.

Enabling view of relational database values in microsoft access (2007)

I am creating a relational database for a friend and I have never used MS Access before. I am trying to make it so that the related values are shown on a table view rather than the numeric representation. For example, instead of
[1][2242], [2][443]
I would like
[1][John Smith], [2][Marilyn Monroe]
(the first value being the primary key and the second being the value linked to another table).
I have read this page about creating relationships between tables but I am still having trouble "viewing" the linked values. Microsoft Access is going to be the only way my friend is going to be viewing these results so that is why it is important to be able to see the correct values.
I have made relational databases before but only with traditional PHP and SQL and so I know what I need to do but I cannot seem to do it.
Any help would be appreciated.
Do not be misled into creating lookup values in tables. Create a form and add comboboxes to display the data from the related table, or use queries.
For example: create form to add records in multiple tables
Or
SELECT Id, Fullname FROM Table1
INNER JOIN Table2
ON Table1.FKID = Table2.ID
You can create the relationships visually in MS Access. You can also build queries in the query design window.