Query With Multiple Outer Joins Gives Wrong Result

Dec 15, 2007

Hello,

My query references 2 related tables: one for persons (PERS) and one for telephone/fax numbers and email addresses (CONT, for Contacts).
The relevant fields are:

PERS
pers_id (long) ---> primary key
pers_forename (text)
pers_surname (text)

CONT
cont_id (long) ---> primary key
pers_id (long) ---> foreign key
come_id (long) ---> foreign key
cont_number (text)

The foreign key come_id refers to a table for contact methods (COME), either "Phone (Home)", "Phone (Work)", "Mobile", "Fax" or "Email".

Now i want to list all persons with their home phone number and email address, also if they don't have one. It seems to be impossible to get it ...
I will explain what happens. Lets start simple: first list all persons with their home phone number (come_id = 1):
SELECT PERS.pers_forename, PERS.pers_surname, CONT.cont_number AS Phone
FROM PERS LEFT JOIN CONT ON PERS.pers_id = CONT.pers_id
WHERE (((IIf(IsNull([come_id]),1,[come_id]))=1));
This works fine. The IIf expression is necessary since we are dealing with an outer join: not all persons have a home phone number. If we would simply put "WHERE come_id = 1" then the query produces only the persons that have a home phone number.

But now i also want to see the email address (come_id = 5):
SELECT PERS.pers_forename, PERS.pers_surname,
CONT.cont_number AS Phone, CONT_1.cont_number AS Email
FROM CONT AS CONT_1 RIGHT JOIN
(PERS LEFT JOIN CONT ON PERS.pers_id = CONT.pers_id)
ON CONT_1.pers_id = PERS.pers_id
WHERE (((IIf(IsNull([cont].[come_id]),1,[cont].[come_id]))=1)
AND ((IIf(IsNull([cont_1].[come_id]),5,[cont_1].[come_id]))=5));
It seems perfectly logical: i added a second alias CONT_1 for the email address. Since this is also optional we have a second outer join, and the WHERE condition should also use an IIf expression.
The result is not correct though: the resulting recordset shows only the persons that have both a home phone number and an email addres or neither!
I have a lot of experience with SQL and queries, but i know i am not infallible. Nevertheless i am quite convinced that i should get all the persons: those that have a home phone number or an email address, or both or neither ...
I hope that someone of you can explain this.

View Replies


ADVERTISEMENT

Help Please With Multiple Outer Joins To Return All Records From Main Table

Jun 5, 2007

I have this query in design view and in an asp page and it works fine:

SELECT dbo_feedback.*, dbo_origin.originName, dbo_product.prodname, dbo_category.catName FROM dbo_product INNER JOIN (dbo_origin INNER JOIN ((dbo_feedback INNER JOIN (dbo_category INNER JOIN links_cat ON dbo_category.catID = links_cat.CatID) ON dbo_feedback.id = links_cat.FeedbackID) INNER JOIN links_product ON dbo_feedback.id = links_product.FeedbackID) ON dbo_origin.originID = dbo_feedback.origin) ON dbo_product.prodID = links_product.ProductID;

BUT, I want to return all feedback entries, even if they have no matching Product or Category. :confused: When I change the inner joins to outer joins I get a syntax error in the browser window. I changed the join type in the relationship diagram in Access and tried to recreate this in query designer, but Access says the statement cannot be executed because of ambiguous outer joins.

FYI, one feedback can have many products, many categories, and only one origin. I have the joins correct and enforced.

Please help, thanks!!!

View 1 Replies View Related

Ambiguous Outer Joins?

Jul 26, 2005

Attached is a pdf of the query window showing the relationships and table structure; (sorry for the quality) the linkage is also permanent at the relationship window. I created a form (columnar) of Rooms; loaded a subform (columnar) of the projects; and then loaded the students (tabular) as a subform on the projects subform. The data entry is flawless; tabs through each field and form to form in sequence.

After entering several rooms data I tested it at the query level by loading the three tables: rooms, projects, and students, and the permanentely established linkage with junctions came in automatically. I thought I was home free--but when I run the query, I get zero records.

When I attempt various joins, thinking this will yeild all records from the many tables and their match, I get "ambiguous outer joins" and it says to run a separate query and add it to the SQL Statement?

Thanks for any help,

Almost funtional in Ann Arbor........

Oh, and thanks Pat Hartman for the tip on linkage -- although I may have screwed it up anyway.

View 11 Replies View Related

Ambigous Outer Joins??????

Feb 5, 2007

I have made a database and have made a query that takes the info from the tables and creates a report. I have a subtable in the form and have added another sub table. When I try to add the new subtable info into the query for the report, I get "ambigous outer joins"??? What the heck is that?????

View 4 Replies View Related

Ambiguous Outer Joins! Please Help.

Nov 23, 2004

I'm new to the Access SQL world but I have a fairly complicated query that needs to be written for a project I'm working on. I am having trouble grasping the join concepts in access. My Query so far is:

SELECT u.user_logon_tx, ur.aff_sec_role_id, r.sec_role_ds, c.sec_cls_ds, o.sec_obj_ds, ci.aff_sec_cls_id, ci.sec_cls_item_ds, IIf(p.perm_in Is Null,0,p.perm_in) AS perm
FROM aff_sec_cls_item AS ci, aff_sec_user AS u, aff_sec_role AS r, aff_sec_user_role AS ur, aff_sec_obj AS o, aff_sec_cls AS c, aff_sec_obj_item_role_perm p,
ci LEFT OUTER JOIN p ON ci.aff_sec_cls_item_id=p.aff_sec_cls_item_id
WHERE u.aff_sec_user_id=1
And ur.aff_sec_user_id=u.aff_sec_user_id
And ur.aff_sec_role_id=r.aff_sec_role_id
And o.aff_sec_obj_id=1155
And o.aff_sec_cls_id=ci.aff_sec_cls_id
And o.aff_sec_cls_id=c.aff_sec_cls_id
And ur.aff_sec_role_id=p.aff_sec_role_id
And o.aff_sec_cls_id=p.aff_sec_cls_id
And o.aff_sec_obj_id=p.aff_sec_obj_id;


I have gotten it to work by using just the tables I'm doing the outer join on but when I add everything else I get the Ambiguous Join error. I wish I was using Oracle Thanks for the help.

View 1 Replies View Related

Ambiguous Outer Joins. What Are They? How To Work Around?

Oct 30, 2007

I have a database in which i am trying to create some forms in order to search for records. The database contains several tables. Some tables are linked using a compound key while others have a single PK. I created the search form which has different searching criteria. Once a user selects the criteria, they hit the search button (there are different buttons for each type of search) the button opens up a form to display all the data. The problem is that there are many tables to report on. I created a form with a subform. The tables associated with the main form are all being retrieved fine. however the subform doesn't seem to work. I created the subform using a query to select all the fields from the desired tables, i gave this query a criteria based on the main form so that the Id's would match. (ie. Main form ID = Firstable in subform.ID)

I got a blank sheet in the subform when i used the search. i presumed that my query was not pulling records because of the referential integrity rules. i went in and changed the relationship rules so that it would include all records from the first table and matching records from the second table. (middle option in the list when editing a relationship) I now get the following error when i try to run the query.

"The SQL statement could not be executed because it contains ambiguous outer joins. To force one of the joins to be performed first, create a separate query that performs the first join and then include that query in your SQL statement."

Could someone please tell me what this means as the help is... how shall we say it.. written in true Microsoft Fashion.

And though it tells me how to fix it, i'm not really sure what it's telling me to do. I am using Access2003 But the Database is in an access 200 file format.

Thanks.

View 3 Replies View Related

Error 3258 Ambiguos Outer Joins

Jun 13, 2007

Hi there. I have this query:SELECT [Range Plan 2006].[Parent Category] AS Expr1, [Range Plan 2006].Attribute AS [Sub category],[This Year All Prog].Category, [This Year All Prog].Product, [Description Master].Description, [This Year All Prog].SumOfQty AS [TY Cum Qty], [This Year All Prog].SumOfValue AS [TY Cum Value], [This Year All Prog].AvgOfMargin AS [TY Cum Margin],[Last Year All Prog].SumOfQty AS [LY Cum Qty], [Last Year All Prog].SumOfValue AS [LY Cum Value], [Last Year All Prog].AvgOfMargin AS [LY Cum Margin], [Last Year All Wk].SumOfQty AS [LY Wk Qty], [Last Year All Wk].SumOfValue AS [LY Wk Value], [Last Year All Wk].AvgOfMargin AS [LY Wk Margin], [This Year All Wk].SumOfQty AS [TY Wk Qty], [This Year All Wk].SumOfValue AS [TY Wk Value], [This Year All Wk].AvgOfMargin AS [TY Wk Margin], [Weekly Product Sales Analysis Stock].Qty AS [Total Stock], [Weekly Product Sales Analysis Stock].[Outstanding PO's], [Weekly Product Sales Analysis Stock].[Total Commitment] AS [Total Commit], IIf(IsNull([Product List - New].product),"",IIf(Year([Product List - New].[date entered])<Forms![Menu - Weekly Reports]!Year,"","NEW")) AS NEW, [Range Plan 2006].[Product Code] AS Expr2FROM [Range Plan 2006], ((((([This Year All Prog] LEFT JOIN [Last Year All Prog] ON [This Year All Prog].Product = [Last Year All Prog].Product) LEFT JOIN [Last Year All Wk] ON [This Year All Prog].Product = [Last Year All Wk].Product) LEFT JOIN [This Year All Wk] ON [This Year All Prog].Product = [This Year All Wk].Product) LEFT JOIN [Weekly Product Sales Analysis Stock] ON [This Year All Prog].Product = [Weekly Product Sales Analysis Stock].Product) LEFT JOIN [Description Master] ON [This Year All Prog].Product = [Description Master].Product) LEFT JOIN [Product List - New] ON [Description Master].Product = [Product List - New].Product;when I start it, access tells me that there are some ambiguous outer joins. I don't understand so much about outer joins, could you help me plz?Thanks.

View 4 Replies View Related

Using Two Outer Joins To Get A Record Count With Missing Records

Feb 5, 2008

Hello All,

I have three tables: Employees, Gender, Diversity. Both the Gender and Diversity tables are one to many relationships with the Employees Table. I am trying to run a query that will output a count of all diversities and genders. For example:


Diversity-----Gender-----Employee Count
White----------Male---------------1
White----------Female------------5

Asian----------Male---------------3
Asian----------Female----------<Blank>

Hispanic-------Male-------------<Blank>
Hispanic-------Female----------<Blank>


I am trying to get all counts, even if the combination of diversity/gender is not in the employees table. I am going to use that information in a Crosstab query.

What I thought would work was do a Left Join For Diversity and Employee such as:

SELECT Diversity.[Diversity Description], Count(Employee.ID) AS CountOfID FROM Diversity LEFT JOIN Employee ON Diversity.ID = Employee.Diversity GROUP BY Diversity.[Diversity Description];


Then, do a Left Join for Gender and Employee such as:

SELECT Gender.[Gender Description], Count(Employee.ID) AS CountOfID
FROM Gender LEFT JOIN Employee ON Gender.[Gender ID] = Employee.Gender GROUP BY Gender.[Gender Description];

And then do a Union. But that doesn't work.

Any thoughts or comments would be much appreciated!

Thanks,

Jon

View 1 Replies View Related

Access Giving Wrong Result Using Sql Query

May 10, 2012

I am using a MS access mdb file to display some record from oracle database using odbc connection.I have a table (linked table) called map_detail in mdb as well as oracle with same table structure.I formed one query in mdb (sql query) select * from map_detail where batch_no="SSO15121".It is always fetching some other result, but when I am changing the query by changing the batch no "SSO15148" it is working fine. I noticed that for cases it working.

View 3 Replies View Related

Multiple Joins In Multiple Table Search Query

Sep 21, 2004

I am trying to create a simple Search form in Access where a user can select a desired record and query multiple tables using the inputs.

I would like them to be able to query Retailers, Distributors and Products.

The 6 tables are linked as follows:
Although some of these tables are not included in the query, they are required to ensure relationships.

Retailers -- Uses (RetailerID,DistributorID) -- Distributors
Retailers -- Orders (RetailerID,ProductID) -- Products

All retailers have at least one distributor BUT a retailer may or may not have ordered any products.

I have created my form but the query linked to the form is having some trouble. It is only selecting those records that have ordered products. For example, if I query a retailer name only and it does not have any ordered products, it will not display. Is there a problem with the table joins? The SQL for the query is displayed here:

Code:

View 5 Replies View Related

Multiple Joins

Jul 24, 2007

Hello,
I have the following code for a multiple join:

INSERT INTO [AppendAllFields]SELECT [TreatyList].[Treaty] AS [Treaty],[MLAC 42 Treaty Xref ER].[tai treaty] AS [TreatyType],[txn 01/04].[Policy_Number]
(and more other fields from [txn 01/04] table)
FROM [txn 01/04] INNER JOIN [MLAC 42 Treaty Xref ER] ON TRIM([txn 01/04].[Policy_Number]) = TRIM([MLAC 42 Treaty Xref ER].[Polnum])
INNER JOIN [TreatyList] ON TRIM([MLAC 42 Treaty Xref ER].[tai treaty]) = TRIM([TreatyList].[TreatyNo]);

Basically, the txn 01/04 table has a corresponding Polnum field in the MLAC 42 table, and MLAC 42 table has a tai treaty field, which corresponds to TreatyNo in TreatyList table.

However, when I tried to run this, I got an Syntax error.

Could anyone please help?

Thanks!

View 4 Replies View Related

Queries :: Search With Multiple Fields Result From Query

Dec 26, 2013

I want to make a form which will allow me to get data from a query and search using 3 fields parallel.

Attached the database in 2010 format.

Password of the db is "nolimit".

The query PTM & Equipment should be bound with the form and

If I enter month, PTM and equipment need rest 2 fields displayed.

Like choosing the above 3 fields from the drop down , the next 2 text box should display the rest two fields.

View 3 Replies View Related

Queries :: Display Multiple Rows Into One Row Query Result

Mar 25, 2013

I have a result for a query made from four different tables for which I would like to refine the result of this query grouping multiple rows into columns.

Attached is a pdf file showing the results being obtained by my query and underneath is how the result would like it be after running the query.

I am currently using Access 2010.

View 5 Replies View Related

Multiple Inner Joins Question

May 3, 2006

I am trying to set up a file compare process. I load the two files into two "matching" tables (there is a key field). I have a series of queries which find any differences in the various fields and displays them. My problem is that one field (Field4 - a tran code) is coded 1,2,3 in one file and A,B,C in the other. I have set up a third translation table with two columns, each row showing the matching codes (1/A, 2/B, 3/C, etc). I want to find corresponding rows in FILE1 and FILE2 (matched on KEY) where tran codes (Field4) do not match (ie a "1" in File1 but NOT a "A" in FILE2).

I have not been able to get the two inner joins to work. Can some one help.

This is my last attempt:


FILE1: KEY-Field1-Field2-Field3-Field4
FILE2: KEY-Field1-Field2-Field3-Field4
(Field4 is the code that needs to be translated)

FILE3/numeric/alphabetic
1 A
2 B
3 C
4 D


SELECT FILE1.KEY,FILE1.Field4, FILE2.Field4
FROM
FILE1 INNER JOIN FILE2 ON FILE1.key = FILE2.key
INNER JOIN [FILE3] ON (FILE1.Field4 = FILE3.alphabetic)
WHERE FILE2.Field4 <> FILE3.numeric.

Hope this makes sense.

Mac

View 3 Replies View Related

Multiple Left Joins From Same Column

Sep 8, 2011

I have a table (Table A) that includes every number that's been dialed in our call center. I have another table (Table B) that has account numbers and three different phone fields for each account.

What I initially tried was to left join the Dialed Number column from Table A to all three phone number columns in Table B. This produces no results. If I only join Dialed Number to Phone Number 1 (for example), I get results, however, if the agent dialed one of the other two numbers, it's not going to show up.

View 1 Replies View Related

Read/Write Queries, Multiple Joins...

Jun 30, 2005

Okay, take three tables.

AreaTable
AreaID
AreaName
Percent

GangTable
GangID
Area_ID
Speed

MasterTable
MasterID
Station
Description
Area_ID

The Relationships

AreaTable.AreaID 1---------> (inf) GangTable.Area_ID
AreaTable.AreaID 1---------> (inf) MasterTable.Area_ID


Initially the query below used Inner Joins, however that limits my list, when i want to see ALL elements from the MasterTable no matter what, thus my inner joins became left and right joins as follows.

Simple Query: Query1

SELECT MasterTable.Station, MasterStable.Description, MasterTable.Area, AreaTable.Percent, GangTable.GangID, GangTable.Speed
FROM (AreaTable RIGHT JOIN MasterTable ON AreaTable.AreaID = MasterTable.Area_ID) LEFT JOIN GangTable ON AreaTable.AreaID = GangTable.Area_ID;


This should simply display All Records in MasterTable, (Multiple Times if Necessary) listing all the elements of AreaTable that are Linked to the MasterTable, and all elements from GangTable that are linked to AreaTable. It does this, and displays them nicely. But I can't edit the fields. I get the result:

1 | Station One | Area 1 | 45% | 204 | 1000
1 | Station One | Area 1 | 45% | 304 | 500
1 | Station One | Area 1 | 45% | 404 | 750
2 | Station Two | Area 1 | 45% | 204 | 1000
2 | Station Two | Area 1 | 45% | 304 | 500
2 | Station Two | Area 1 | 45% | 404 | 750
3 | Station Three | Area 2 | 75% | 254 | 800
3 | Station Three | Area 2 | 75% | 354 | 600
3 | Station Three | Area 2 | 75% | 454 | 700


So you can see that Area 1 has multiple Gangs (204,304,404) and Multiple Stations (1,2). If you do a simple set up like this, you'll find that you can't change the Description field (Rename "Station One" to "Hello World"). It just doesn't work, no matter which way I've tried, I can't seem to make a Query that presents all the information from MasterTable and All the Information IN AreaTable and All the Information in GangTable which will allow me to also edit the fields.

Any Help would be most appreciative, I'm tearing my hair out on this one.
Thanks,
Jaeden "Sifo Dyas" al'Raec Ruiner

ps - It just seems that with Junction Tables and all the many to many relationship designs I have tried, you'd be able to change the non-related fields. I understand that you can't change the "ID" fields, but the others should be editable.

View 2 Replies View Related

Queries :: Conditional Query To Post Result In Field And Filter Result Records?

Mar 5, 2014

I am working with Access 2010, on vista. What I have is a query made up of two tables, one product the other inventory. (see below) query.jpg

In the product table i have a field called "minimum reorder level". In the inventory table i have two fields one called "number in stock" and "number on order". What i want to happen is "number on order" to be filtered by the result, if the "number in stock", is less than "minimum reorder level", if it is, have the result placed in the "number on order" field. EG. if the "number in stock" = 2 and the "minimum reorder level" = 5 then 3 would be placed in the field "number on order" and only the second record from the query would be visible (see below) Query result.jpg The result of this would mean that the field "number on order" would be populated with the result and the and query would also use this to filter the record.

View 1 Replies View Related

General :: Adding Count To Result Of Query Depending On Month And Result

Aug 18, 2013

I want to add a number to my results within a query depending on the month and how many results. For example I have 10 results in my query 3 from January, 5 from March and the rest from April. The 3 from January would be 1,2,3. The five in March would be 1,2,3,4,5 and so on. Is it possible to do?

I'm using access 2003.

View 4 Replies View Related

How To Right Outer Join Several Tables In A Query?

Aug 23, 2006

Hi!

Thanks for all help so far, this forum is great ;)

I have 3 tables: Order, Product and Names.

I want to list All orders, no matter if they hold a key to a product or not, and no matter if this product has been given a name (in the table name) or not.

To make it even more complicated, the customer can give upp to 16 namesuggestions, they are all numbered from 1-16. But If they are given a namesuggestion, i only want to present the first one (nr 1).

Relations: 1 order -> 0 or 1 product.
1 order -> 0 or up to 16 names, of which i only want to display nr 1.

Any suggestions?
I am thinking of preparing the data in a temporary table, but would be glad if i did not need to do so....

View 1 Replies View Related

Help With Outer Join Query In Acess 2003

Apr 11, 2007

hello,

I have query , which has got 2 outer joins. The query is:

SELECT A.Project_ID, A.Title, A.comm1 AS Comments, A.Partner AS PM, A.Staff_Assigned AS TL, A.Contact_Name AS FL, A.MD, A.Status, A.Project_Type,
ISNULL(B.Delivered_Date, B.Delivery_Date) AS Start_Date, ISNULL(C.Delivered_Date, C.Delivery_Date) AS End_Date
FROM dbo.PROJECT A LEFT OUTER JOIN
dbo.PROJDATE B ON A.Project_ID = B.Project_ID AND B.Date_Type = "Start Date" LEFT OUTER JOIN
dbo.PROJDATE C ON A.Project_ID = C.Project_ID AND C.Date_Type = "End Date"

Can anybody help me out the error with this. I get an error : at dbo.PROJDATE B ON A.Project_ID = B.Project_ID AND B.Date_Type = "Start Date" .

Do I need to use any parantheris or change anthing.

Thanks

View 5 Replies View Related

Edit Fields In An Outer Join Query

Mar 13, 2008

I have 2 tables (tblItemsQB and tblItemInfo) that have a 1 to 1 relationship linked by the "PartNumber" field. The tblItemsQB table contains a description field and 2 price fields (this table is downloaded from Quickbooks). The tblItemInfo table contains additional fields with information on the part that isn't contained in Quickbooks, like OrderType, Phase, SubSystem.

I import the items from QB into tblItemsQB and then do an outer join with tblItemInfo to link all the information for the part. If I have created a new part in Quickbooks, when I do the outer join (I include all records from tblItemsQB) I can see the new part but since the part number doesn't exist yet in tblItemInfo, I can't add the information to the fields in that table.

What is the easiest way to create the new PartNumbers (those that exist in tblItemsQb but not in tblItemInfo) in the tblItemInfo table so I can add the other information to it?

thanks
mike

View 2 Replies View Related

Queries :: If There Is No Result In Query Need To Have Default Result Zero

Oct 12, 2013

I there is no result in query, I need the default result zero in my form field. I only use query wizard to create queries.

View 5 Replies View Related

Query With Many Joins

Feb 4, 2007

hi

i have 4 tables: tbEmploye, tbCirculaire, , tbCategorie, lienCirculaireEmploye


tbCategorie (every circulaire have a category)
-cirIdCategorie
-cirCategorie

tbEmploye
- empID
- empPrenom
- empNom
- empNumeroEmploye
- empMotPasse

tbCirculaire
- cirID
- cirIdCategorie
- cirNumero
- cirDescription
- cirDate
- cirNomFichier


lienCirculaireEmploye (link circulaire to employe
- cirNumero
- empNumeroEmploye
- dateLecture


SELECT tbCirculaire.cirNumero,
tbCategorie.cirCategorie,
tbCirculaire.cirDescription,
tbCirculaire.cirNomFichier,
tbCirculaire.cirDate,
tbEmploye.empNumeroEmploye,
tbEmploye.empPrenom ,
tbEmploye.empNom,
lienCirculaireEmploye.dateLecture
FROM (tbCirculaire INNER JOIN lienCirculaireEmploye ON tbCirculaire.cirNumero = lienCirculaireEmploye.cirNumero)
INNER JOIN tbEmploye ON lienCirculaireEmploye.empNumeroEmploye = tbEmploye.empNumeroEmploye
INNER JOIN tbCategorie ON tbCirculaire.cirIdCategorie = tbCategorie.cirIdCategorie
WHERE tbCategorie.cirIdCategorie IN ( 1,2 )


with this query, i get error: 3075

Syntax error (missin operator) in query expression
lienCirculaireEmploye ON tbCirculaire.cirNumero = lienCirculaireEmploye.cirNumero)
INNER JOIN tbEmploye ON lienCirculaireEmploye.empNumeroEmploye = tbEmploye.empNumeroEmploye
INNER JOIN tbCategorie ON tbCirculaire.cirIdCategorie = tbCategorie.cirIdCategorie


any idea?

View 2 Replies View Related

Query Joins

Sep 4, 2007

Hi all,

Simple problem, but my access and sql skills are very limited.

I have two tables. One containing a group of frequent customers with a column called 'member status'. Another table containing a group of non-customers. The addresses in both tables have been matched using group1 software.

I would like to create a query that shows me all the customers with 'member status' = 'A' and all the non-customers who live at the same address.

When i run the query, everybody comes up as 'member status'=A. I think this is because there is no 'member status' field in the non-customers table, and i have failed to make the appropriate join or parameters. Is there a way to design a query that will show 'member status' for those who have it, and will display a null for those who do not?

Any help is appreciated thank you!

View 4 Replies View Related

Outer Join Creating Duplicates In Dynamic Query Search Results

Jan 22, 2008

Now that i have read this again, i think it could be summed up into one question...if i have a form based off a query with an outer join that has various duplicate records, is there a way to use the recordset in an if statement that says something like if this recordID = that recordID then dont show one of them...hence not showing the duplicate field data in the form.If you want a more specific description of the problem, read on, otherwise don't read on.Hi All,So I hope I can explain this ok....here goes....I have a search using dynamic queries: I have a form where the user can put in various information he wants to search to find a record. In this case it is searching for Hotels. So the user can search a country to see all of the hotels in that country. Also, the user can search an interest like Beach or Nature to see those hotels that apply. Obviously each hotel may have more than one interest so I have a 1-many relationship with a table called Hotels_Interests.The kicker, and you can likely already see why, is that the user does not have to fill out every search field. He may search Country&Interest, or just one or the other, or leave everything blank to see all hotels in the database. The results are simply ordered by HotelID or something like that in a form that is based off the dynamic query. The dynamic query is of course just based off the query i explained, but with criteria added in.The problem is with the query that i am basing this search off of. Right now it has the main Hotels table as well as the 1-Many table Hotels_Interests and even another that is 1-Many Hotels_HotelTypes (say All Inclusive, Resort, etc.). So this query has various 1-Many tables as well as the main Hotels. Now, if i fill in all of those fields in the search form, there will obviously not be any duplicates returned, which is super. But if i leave Hotel_HotelTypes search field blank, i will be returned with the same hotel twice or more times, which is my problem, because i want nice search results.I have heard of people using Union queries to get rid of duplicates but this obviously does not solve my problem as i do not want to just get rid of these entries. What i think i want is some VBA method or whatever of showing in my search results each HotelID that meets the search criteria only one time.Right now i have it working with If statements that say if the user has left a specific search criteria blank then base the search off a different query. This is obviously crazy and is only a temp fix. Now that i want three or more 1-many tables in my query, i would be talking about if statements for like 6 or more queries, insane.I apologize for the length of this, but i wanted to be perfectly clear. I feel like it should be not too hard, like using a record set for the form and not showing certain records or something, but i am not sure how to do it.Thanks so much. Dillon

View 4 Replies View Related

Queries :: Nested Query - Left Outer Join Not Returning All Records

Oct 1, 2014

I have a simple nested query that is not working as expected. My inner query returns 102 records but when I run with outer query I only get 96 records. Below is my query, I don't really want to pull the same fields from both tables but I was doing to test. The values that are missing are those that don't exist with the monthenddate 8/31/2014 - a left join should fix that but doesn't seem to be working ..

Code:

Select distinct a.entity, a.gl_account,a.profit_center,[Open Items_1].profit_center,[Open Items_1].gl_account,[Open Items_1].entity
from(
SELECT DISTINCT [Open Items].entity, [Open Items].gl_account, [Open Items].profit_center
FROM [Open Items]
)a
left outer JOIN [Open Items] AS [Open Items_1] ON
(a.profit_center = [Open Items_1].profit_center) AND (a.gl_account = [Open Items_1].gl_account) AND (a.entity = [Open Items_1].entity)
Where ([Open Items_1].MonthEndDate=#8/31/2014#)

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved