473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Multi table queries ACCESS- URGENT HELP

Hi

I am pretty new to ACCESS. I have created some small databases previously. I need to run a simple query searching for a USERNAME which will gather information from five to ten tables containing seperate bits of information and combine them into a report. The primary key on all of the tables is the username.

AS AN EXAMPLE:

TABLE 1

USERNAME
DATE JOINED
NAME
ADDRESS

TABLE 2

USERNAME
FAVOURITE FILMS
FAVOURITE ACTORS

TABLE 3

USERNAME
DATE OF PURCHASE
FAVOURITE SHOP

I would like to create a search for a single username which would find matching results in each table and then combine the relevant information:

DATE JOINED
NAME
ADDRESS
FAVOURITE FILMS
FAVOURITE ACTORS
DATE OF PURCHASE
FAVOURITE SHOP

all in one report. I am using multiple tables instead of combining the info into one table, because each of the tables is filled in by a different department and seperate tables would prevent confusion for those filling the information in. prevent confusing found it easier so separate the information into individual tables. I thought of doing a UNION query but was unsure how the user would enter their desired query prior to running the UNION query. Please help!!!!!
Feb 15 '07 #1
7 2277
MMcCarthy
14,534 Expert Mod 8TB
Firstly you should have a primary key on Table1 (e.g. UserID) which would be number based and use that as the link to the other tables. Using USERNAME as a text field has two problems. 1) It is harder for the database to run queries based on a text field join. If there are any difference in spelling etc in these fields the tables won't join.

Secondly if any of these tables has multiple records for the user the query won't be updatable.

However, the query you need is...

Expand|Select|Wrap|Line Numbers
  1. SELECT  USERNAME, DATE JOINED, NAME, ADDRESS, 
  2. FAVOURITE FILMS, FAVOURITE ACTORS,  DATE OF PURCHASE,
  3. FAVOURITE SHOP
  4. FROM Table1 LEFT JOIN 
  5. (Table2 LEFT JOIN Table3
  6. ON Table2.USERNAME = Table3.USERNAME)
  7. ON Table1.USERNAME = Table2.USERNAME;
  8.  
You should probably take the time to read the following tutorial.

Normalisation and Table structures

Mary
Feb 15 '07 #2
Hi

Firstly I would like to thank you for your quick response!!!

Each of the tables currently have the username as the primary key. I find that I can create a query combining two to three tables, and a simple search via username yield a correct result every time. However I recieve a problem when I add a more tables, which I thought would simply add extra fields to my results. However this is not the case, when I run a search I see the field headings only with no results whatsoever even though I know my search is correct. If I change the primary key to a number as you suggest would the results display correctly ??

thank you.
Feb 15 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
Hi

Firstly I would like to thank you for your quick response!!!

Each of the tables currently have the username as the primary key. I find that I can create a query combining two to three tables, and a simple search via username yield a correct result every time. However I recieve a problem when I add a more tables, which I thought would simply add extra fields to my results. However this is not the case, when I run a search I see the field headings only with no results whatsoever even though I know my search is correct. If I change the primary key to a number as you suggest would the results display correctly ??

thank you.
I think your problem is in your table design. UserID (replacing USERNAME) should only be the primary key on the first table. Each table should have it's own primary key and UserID should only be a foreign key in the other tables.

Did you check out the tutorial link. This is explained there in a lot more detail.

Mary
Feb 15 '07 #4
Hi,

Wow thank you, I have been able to modify my relationships and now I have been able to join all the tables I require together. I totally restructured the tables and now gather clear results from any query I run. I would like to thank you for helping to teach me to resolve this issue.

There is another small problem which I have found however which I would really appretiate some help on if possible. The relationships in this example does not relate to the new relationships I have created. I am simply wishing to illustrate my thought process on what I would like to achieve. In one of the tables I have the following fields as an example:

TABLE 1

USERNAME [Primary Key]
FAVOURITE FILMS (eg action/Adventure/comedy)
FAVOURITE ACTORS

I would like to have another table with the following information which will list every single type of film the particular customer watched in each genre:

TABLE 2

GENRE
FILM TITLE 1
FILM TITLE 2
FILM TITLE 3
etc

I would like to be able to link the FAVOURITE FILMS link in table 1 to the GENRE link in table 2 as they would contain the same information (ie a genre code). The problem I am having is potentially I would need to enter an unlimited amount of film titles. If I made GENRE in the 2nd table the primary key, duplicate entries would not be allowed so I would need to enter FILM TITLE 1- 10000 potentially to accomodate an unlimited amount of films the customer may watch. However If I did not make it the primary and use a smaller number of entries say FILM TITLE 1- 10 on the table. This would allow the user to generate a new table of entries as and when they are needed on TABLE 2. If a query was run on the user however I would recieved duplicate details from TABLE 1 for each time a new list of entries for table 2 was generated. WHat do you think would be the best way of solving this issue?

thank you very much
Feb 20 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
In this case I would have a tables called Genre, Film, Actor and a table called FavouriteFilms

Genre
GenreID (Primary Key)
GenreName

Film
FilmID (Primary Key)
FilmName
GenreID

Actor
ActorID (Primary Key)
ActorName

FavouriteFilm
FavFilmID (Primary Key)
UserID
FilmID

FavouriteActor
FavActorID (Primary Key)
UserID
ActorID

You don't need to refer to Genre in FavouriteFilm as the Genre is already recorded in in the Film table for each film. Also each film and actor only needs to be added once to the film and actor tables.

Mary
Feb 20 '07 #6
Hi,

Thanks for that. My Access database has come on in leaps and bounds thanks to you.

I have another question and I'll give you another example to illustrate it, I hope you can help. If I had a table like this with the top 5 film ID's:

Table

Account ID
FILM ID 1
FILM ID 2
FILM ID 3
FILM ID 4
FILM ID 5

would it be possible to create a query which would allow the user to type in a film ID once but the system would search each field FILM ID 1 - 5 without the need to typew in the ID five times??

Yours gratefully
Feb 23 '07 #7
MMcCarthy
14,534 Expert Mod 8TB
Hi,

Thanks for that. My Access database has come on in leaps and bounds thanks to you.

I have another question and I'll give you another example to illustrate it, I hope you can help. If I had a table like this with the top 5 film ID's:

Table

Account ID
FILM ID 1
FILM ID 2
FILM ID 3
FILM ID 4
FILM ID 5

would it be possible to create a query which would allow the user to type in a film ID once but the system would search each field FILM ID 1 - 5 without the need to typew in the ID five times??

Yours gratefully
Sorry I don't understand what you mean by the question. You should probably post a new question for this anyway.

Mary
Feb 23 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Daniel | last post by:
I use an Access database to basically take data exports, import them, manipulate the data, and then turn them into exportable reports. I do this using numerous macros, and queries to get the data...
0
by: deathyam | last post by:
Hi, I am writing an application in Excel 97 in which the users click a button and data is saved/read to and from an Access 97 database on the LAN. I am concerned about performance because there...
14
by: Sonic | last post by:
I have an MDE file that is growing exponentially (from 3,900 KB to over 132,000 KB today). I am not saving data in this MDE, although I use a mix of offline and SQL tables for Read Only querying. ...
0
by: Gareth Stretch | last post by:
Hi Guys. i am using C#.net connecting to an Access database using OleDbConnection i am using the following select Statement to join 3 tables string strdvds = "SELECT dvd.name,...
3
by: BrianDP | last post by:
I have a database with a split front end/back end. There is a key table in the back end called Catalog, and it is sort of a central key table for all sorts of things. It's a list of all the jobs...
6
by: Mike S | last post by:
Hi all, A (possibly dumb) question, but I've had no luck finding a definitive answer to it. Suppose I have two tables, Employees and Employers, which both have a column named "Id": Employees...
6
by: gabry.morelli | last post by:
Hi everybody, my company has an issue and I have to solve it. I have to create a multiple users application, its basically a form that stores data on just one database table. To make it faster...
6
by: dbuchanan | last post by:
There are three parts to this 1.) How do I cascade menus? 2.) And, how do I cascade menus with a multi-select CheckBoxList?
3
by: jonceramic | last post by:
Hi All, I need to know the best way to set up a datawarehouse/materialized view for doing statistics/graphs in Access. My crosstabs and unions are getting too complicated to crunch in real...
9
by: Mourad | last post by:
Hi All, Is it possible to create a Make Table query in access (2.0 and 2003) that creates the table into a SQL Server database? Following the steps: 1- Create New Query 2- Set Query Type as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.