Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Join two table fields to one field

Posted on 2004-04-17
13
Medium Priority
?
205 Views
Last Modified: 2010-05-02
I have two tables "Locations" and "Hotel". i wanna join:

Locations.Locations and Hotel.Hotel

in one field. so you can select from a list with both the values from locations and hotel. Im using Microsoft Access by the way. i have tried with SELECT Locations.ID, Locations.Locations, Hotel.ID, Hotel.Hotel FROM Locations, Hotel;
but that doesnt seem too work i get alot of the same values. Im only working in Access so i only have the option of creating one single SQL query. i have tried with union aswell but it doesnt work either...
0
Comment
Question by:illion
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
13 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 10851951
SELECT Locations.ID,
            Locations.Locations,
            Hotel.ID,
            Hotel.Hotel
FROM   Locations
           Inner Join Hotel On Locations.Locations = Hotel.Hotel
0
 

Author Comment

by:illion
ID: 10851981
hmm ok, but the Locations.Locations and Hotel.Hotel wont be the same value, thats why i want to add both to one field, cause locations wont contain the names of the hotels, so instead of writing the hotel names in locations.locations im trying to just join them.
0
 

Author Comment

by:illion
ID: 10851990
I have another table Transfers and in that table i have a field called From and it can both be from a Location or a Hotel, so i want to be able to choose from both the values in Locations.Locations and Hotel.Hotel.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 10851991
Post some sample data and the desired output.
0
 

Author Comment

by:illion
ID: 10852004
Table1 : Locations
---------------------------------------------------------
ID | Locations
1     Beach Bar

Table2 : Hotel
---------------------------------------------------------
ID |        Hotel            | Address | City | Zip
1        Turtle beach       blabla 23   bla    123

Table3: Transfer
---------------------------------------------------------
ID | From | To
1     "Here i want a list with both the values from Hotel.Hotel and Locations.Locations"
0
 

Author Comment

by:illion
ID: 10852007
if i write SELECT Hotel.ID, Hotel.Hotel FROM Hotel
i only get the hotels not the other locations and if i do the other way around i only get the other locations
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 10852015
So what is the relationship (which column) between the Locations and Hotel tables.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 10852017
The same goes for your Transfer table.

Finally, what is your desired output.  Please give an example.
0
 

Author Comment

by:illion
ID: 10852019
there is no relationship between them its just that i have other Locations in a separate table and Hotels in the Hotel table, and i want to be able to choose from both when i choose transfers.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 10852024
If there is no relationship between the three tables, than I have no idea.
0
 

Author Comment

by:illion
ID: 10852027
I dont want any output, im only working inside a database so if theres gonna be any output it should be that Transfer.From should be able to contain both the value from Locations.Locations and Hotel.Hotel. I guess i want a relation between:
Transfer.From -> Locations.Locations & Hotel.Hotel
0
 
LVL 2

Accepted Solution

by:
DANNYMAC earned 200 total points
ID: 10853890
Ok so the goal is to get all the Hotel.hotel entries and all the Location.location data into a single field in a recordset?  Correct.
There is no key that related location to hotel.  so...

Select hotel from hotel
union
Select location from location;

This would return a list from the above example of
 Turtle beach
 Beach Bar

Your fields must match so if you want to return more than 1 field you can use...

Select hotel as place, ID from hotel
union
Select  location as place , ID  from location;

However if you want to create a record that has the ID,  To, and From columns you would do something like...
Assuming that they are coming from a location to the Hotel.  You must decide which what the data is going.

Select  Hotel.Id,  Location as PlaceFrom, Hotel as Destination
From Hotel inner join Location on Hotel.ID = location.ID

Assuming that the ID field, that which relates the 2 tables, is an identifier for each client or customer.
Hope this help.
0
 
LVL 2

Expert Comment

by:DANNYMAC
ID: 10856376
Glad to help, thanks for the points
D
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question