Query Multiple Tables Using INNER JOIN And Multivalue Fields
Jan 28, 2013
Here is my current table structure (I have omitted some fields from this example and have given some sample data in italics to make the table structure more clear.
tblEmployees
ID (autonumber) 3
EmployeeName John
EmployeePhone 555999555
EmployeeLocation New York
tblClients
ClientID (autonumber) 1 , 2 , 3
ClientName ABC Company , XYZ Company, PQR Company
fkeyLocationID
tblLocations
LocationID 1 , 2
Location New York , Chicago
The junction table tblEmployeeClients only stores ID of the Employee and in the second column (which is a multi-valued field), the ID of each of the clients the employee Supports.
I am trying to generate a report that lists say, EmployeeName alongside the clients supported by the Employee (listing the client location is not required, however, it would be good to know how to do that as well).
The report (for the example above), should look like this:
Name Clients Supported
John ABC Company, PQR Company
Currently, I am able to get :
John 1, 2 i.e the client ID for the clients that the employee supports instead of the corresponding company names.
Is there another field that can be used beside the lookup field in an Access table? I am currently using the lookup field as a multivalued lookup field and I am limited to the the things I can do with it when creating a report or a query on that field. Is there a similar field in Access 2010 that has the same look as a lookup field and allows for multiple values to be selected?
I have a database which is working ok where i have a set of tasks in a table with a bunch of irrelevant fields. On creation of a task i assign users to those tasks into a multivalue field(this is all fine).
Using a query i can report to each user what tasks they are assigned to easily.
To make the database more complex i would now like to assign these users to a task and then allow them to assign there portion complete (but not the whole task complete) but i can not assign a bool variable to a .value (can i?).
My thoughts are my database is just not set up for this by using the multivalue field to hold the assigned users?
ContentTypes ---> Site Content Directory Cats ---> Categories Sierra ---> Store Content for Sierra BrushStrokes ---> Store Content for BS
I have "tried" to create a QUERY for the 4 Tables (The code that I have, originally came with 3-Table Query connection I have added in the 4th Table "BrushStrokes")
This is the Query that I created. Before the code, a little insite
At first there was: RIGHT & LEFT JOIN's, But I would receive this: Error 3258 After not really finding any good examples of how to create the 2- Queries and have then work together as one. I decided to try something else, which was to create all [INNER JOIN]'s Which got rid of the Error, and the code still will not work in my site. ======== Microsoft JET Database Engine error '80040e14' Syntax error in JOIN operation. =======
So, here is the code, please let me know what is wrong with it? And if possible, a good example of creating the [2 - Queries] that work as one.
Thank you all Carrzkiss -----------------------SQL QUERY------------------ SELECT Cats.CatID, Sierra.CatID, BrushStrokes.CatID, Sierra.ContentID, BrushStrokes.BSContentID, Sierra.Product_Title, BrushStrokes.BSProduct_Name, Cats.CatDescription, Cats.CatTypeId, Sierra.Product_Th_Image, BrushStrokes.BSThumbnail, Sierra.Our_Price, BrushStrokes.BSPrice, Sierra.Retail_Price, BrushStrokes.BSRetail, Sierra.Aff_Name, BrushStrokes.Aff_Name, Sierra.Brand_Name, BrushStrokes.BSArtistName, Sierra.YAvailable, BrushStrokes.BSStatus, Sierra.Percent_Savings, Sierra.Unique_Product_ID, BrushStrokes.BSProductID, Sierra.Main_Cat, BrushStrokes.BSCol_Cat, ContentTypes.ContentType, Sierra.Product_Description, BrushStrokes.BSDescription FROM ((ContentTypes INNER JOIN Sierra ON ContentTypes.ContentTypeID = Sierra.ContentTypeID) INNER JOIN BrushStrokes ON ContentTypes.ContentTypeID = BrushStrokes.ContentTypeID) INNER JOIN Cats ON (BrushStrokes.CatID = Cats.CatID) AND (Sierra.CatID = Cats.CatID) WHERE (((Sierra.Display)=1) AND ((BrushStrokes.Display)=1)); -----------------------------END SQL QUERY------------------
I have a table that is basically a survey form. The same series of options was available for 35 questions, and the table used to have a text string written for each answer. Because of all the repetitive data, I created a second table that assigned a number value to each of the nine possible options in these 35 separate fields. What happened is that, instead of the same text strings repeated over and over (and taking up real estate), now each of the 35 columns had a single number in them.
Now comes the day of reckoning and TPTB want a query with the raw data and the original text strings back in instead of the numbers. I was thinking doing something along the lines of a DLookup, but I can't seem to make that work in a query correctly. Apart from calling the same table and linking it over and over to the different fields in the original data table (see photo for how insane that is).
I have 10 tables, 30+ fields on each table (every table has the same 'account number' field). I only need from 5 - 20 fields from each table. How do I get the certain fields from each table and put them in a table, query or report?
I am undertaking an analysis of corporate mobile phone data based on data from the phone provider. The base data consists of a number of monthly text files at transaction level for voice calls, data usage, billing/tariff information, international calls/transfers etc. I have set up VBA code to import the text file data into a number of Access tables.I would like to have a way of joining these tables but the only common field is the phone number (a text field with the groups of numbers separated by hyphens).
I confirmed that joining the tables on the phone number text field does not work.My idea was to create an additional table with just one row for each phone number and link that to the other tables by the ID in the new table. I was able to create this table [PhoneNumbers] (by creating a totals query of the phone numbers from the main call transactions table, I then dumped it into Excel and then imported it into a new Access table with an auto-generated ID column).My problem / challenge is how to get the ID column from my [PhoneNumbers] table to appear in each of the other tables so that I can join them effectively. In the Excel-world, I would have used a vlookup function.I even thought of performing this as an interim step in Excel but there are too many records / rows in some of my tables. It seems that the dlookup function is not what Im looking for and even if the IIF function is suitable, I cannot get the syntax to work for me.
In my table, I setup a multivalue field. In the screen, I can check off more than one selection. It stores the selections in the table as value1, value2, value3, etc...which is fine. However, when I go back to review the entry in a report or a screen, it displays it exactly the same as it is stored in the table - value1, value2, value3, etc...Because of size limiations, the field is only so wide, thus it only shows value1, va...and then the rest cut off.
Regardless of how wide I make the field, all of the values will not be displayed, plus, if there is only one value, it will be a waste of space. What is the best way to display one (if there is only one selected) or all of the values selected ? Is there a way to display then vertically, like value1, (next line) value2, (next line) value3 ?
I get tasked to use access very infrequently but now I have been asked to create a database. I am struggling with combining 2 tables. I have different data on each table however I do have a unique Identifier. So on table 1 I have Bud, his height, weight, etc. On table 2 I have Bud his home address, phone #, etc. I am using name "Bud" in this case as my unique identifier. I want to create a query that gives me Bud, his height, phone # etc. I want my query to pull in all records. Bud may only have info on table 1 and Budette could be on table 2 but not on table 1. I would like my query to include all the unique identifiers and as much info as I have in the tables.
I have a table which now contains a couple of hundred records with more than thirty fields each, and will ultimately contain over 1000 records. Some of these fields use the multiple value feature, and the fields and the forms which fill them work beautifully. Now comes the challenge.
Without going into detail that I'm not at liberty to share, I can say that there are different offices which have different people who are responsible in different ways for the work covered in these records. It is possible for each record to have multiple people assigned to it from the same office. This requires setting the control that shows the people from each office to allow multiple values. I need to be able to create a report which will allow me to hand a list of all the records each person is responsible for in the office to the person responsible, in spite of the fact that this will mean records will show up on more than one person's report.
Before I knew that there might be multiple people in the office for each record, I created great reports grouping and ordering by this office's control and field. Now, since they allow and store multiple values, I can't use them any more. I need to be able, as I said above, to get the same effect. I think the answer lies in some sort of calculated field or formula that applies text filters. What I need to be able to do is look in the field for this office and see if a person's name is contained in the field for that particular record, regardless of who else might be in the field, too. I need to be able to use the results from this filter or calculation or formula to generate something I can use in the group and order by processes.
I have two tables "Tab_Issue_1" and "Tab_Issue_2". Tab_Issue_1 has two fields "Issue" and "AssignedTo". Tab_Issue_2 has the same fields. However, the "AssignedTo" is a multi-value field in both tables. I want to append data from Tab_Issue_1 into Tab_Issue_2. I use the following SQL but it pops up this message "An INSERT INTO query can not contain a multi-valued field".
[SQL] INSERT INTO Tab_Issues_1 ( Title, AssignedTo ) SELECT Tab_Issues_2.Title, Tab_Issues_2.AssignedTo FROM Tab_Issues_2; [SQL]
I've been doing some reading on multivalue fields and it seems to be exactly what I'm looking for. My question: Is there a way to use the multivalue field without making it a lookup? I need the user to be able to put multiple values in a field but can't limit them to a list. The field that needs multiple values happens to be for SKU numbers from a large department store franchise.
One work around I've come up with is to have a pop up that asks for the separate sku numbers so they can be used for the value list each time, but then the user also would have to select those from the value list in order to enter it.... too many end user steps.
I want to avoid making 10-15 different fields each for SKU number, Item, and cost... I also need to avoid having to populate my db with the department store's full list of products...
This is my query:- SELECT DISTINCTROW Customer.custName, Sum(Invoice.invAmount) AS SumOfinvAmount, Sum(Payment.payAmount) AS SumOfpayAmount FROM (Customer LEFT JOIN Invoice ON Customer.custID = Invoice.invCustID) LEFT JOIN Payment ON Customer.custID = Payment.payCustID GROUP BY Customer.custName, Customer.custID;
Result:- custName SumOfinvAmount SumOfpayAmount blake $20.00 julie $50.00 kate $375.00 $290.00 steven $200.00
The resulting SQL query returns incorrect invoice and payment totals for Kate. The Sum() function has duplicated. Can anyone tell me how I would change my query to fix this problem?
and what i need to is something that will link all sku 1 category names in a new field with a | divider and then all the sku 2 category names together with | as a divider and so on. the amount of categories is different for every sku.
And if this is easy enough, its not that important though but to delete duplicate category names when it transfers them across to a new field joined together.
And then called this join as a symbol or variable, and then have it use to select the items from these joined tables, can this be done in Access? Here is an example of a code that I created, but it has an error message saying the FROM syntax is incorrect.
Code: SELECT firstJOIN.trainID, firstJOIN.trainName, firstJOIN.stationID, firstJOIN.stationName, firstJOIN.distance_miles, firstJOIN.time_mins FROM (trains INNER JOIN ((station INNER JOIN lineStation ON station.stationID = lineStation.stationID) INNER JOIN bookingLeg ON bookingLeg.startID = station.stationID or bookingLeg.endID = station.stationID ) ON trains.trainID = bookingLeg.tid) as firstJOIN
Can Access do something similar to this, in the FROM statement I joined 4 tables, because each unique fields are in each table and I have to joined them to get those fields. I called this join firstJOIN and in the SELECT statement, I list those columns in the table by calling it firstJOIN.trainID. Can Access do something like this, but syntax it differently?
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?
Hello, exactly how Access 2002 and SQL operate is still a bit fuzzy to me.
In brief: tableAccounts has fields for Signatory1ID and Signatory2ID, and other stuff tableSignatories has ID for a primary key and has SignatoryTypeID as a field tableSignatoryTypes has ID for a primary key and SignatoryType as a field
For each account, on a Form I want to show the Signatory and SignatoryType info for both signatory1 and signatory2. I have tried creating various queries and INNER JOINing the tables and/or queries together, but whenever I manage to get all the information displayed, none of it is editable. Access seems to lock the various text boxes and combo boxes.
I would like to join two tables with one query. Here is the twist though. The first table would have a set of value like so:
0 50 100 300 500 750 1200 1500
the second table would have values as such
0 1000 1300 1500 1750
by just setting up the relationship to show all values from the sirt table and only those from the second table that match I get a list of values that will not work for me. What I would like to reflect in the query is all the values from the first table and if there is for instance no value of 500 in the second table I would like to return 1000. For instance there is a zero in each table so that would be output twice. There is however no value of 50 in the second table so the query would read 50 and null or blank when I would like it to read 50 and 1000 (The next value higher).
A small issue I was wondering of for a few day . Is it possible in SQL query to SELECT multiple fields from multiple tables ? Example for the question is
Code:
dim my_var as String my_var = "SELECT Emp_FName , Emp_LName , Emp_Adress " _ & " FROM Table1 " _ & " AND Emp_Date_Of_Payment , Emp_Sum_Of_Payment " _ & "FROM Table2 " _ & " WHERE Emp_ID = 3 "
Is this code actually valid in SQL gramatics , and is it usable if passed to a Recordset variable ( rs = CurrentDB.OpenRecordset(my_var) ) ? Just FYI - The two tables are not related and I want to keep them that way (If possible relate their records just via SQL/Vba )
In my job we work with several raw data .txt files exported from Oracle ERP system. These data include information about: inventory, sales, backorders, purchase orders, forecasts, product line.
My goal is to put information from all of these imported txt files together to create an easy to use snapshot file.
The common field between al of these files is the item description. I have an issue where records are repeated for several fields every time the same item description is showed. For example for the same product description the january sales forecast QTY is repeated on several rows because there are several orders for this product description. Is there a way to make forecast QTY appear only once but keep the multiple orders and their information?
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....
I am trying to join two tables in a query. One of the tables has only the fullname while another has only the surname (this table is imported from an external database). I need to be able to match the two tables up. Can anyone please suggest how to do this or even if this is possible.
I have two tables with name of accone and the second with the name of acctwo. These two tables are same according to number of columns and also same according to data types and also same according to the column names just the data are difference and also one column (attribute) with the name of ID is same in both tables. Their is a primary key relationship (one-to-one) between these two IDs. I need a query that can combine the data of both of them and can be updated using query. I mean that data of first table and second table must become under one same column not two columns one for first table and second one for second tabel.
I have a table called MiscORders where all the orders are tracked. There is an ID, order number , other fields and ParentorderID fields in it. Whenever an order is modified they create a new order with ordernumber and have the previous order number as the parent. The next time it is amended or closed another order is created with the parent order attached. Here is some sample data
Order ID OrderNum Parent order id 1 MISC 2013-10 2 MISC 2013-10A MISC 2013-10 3 MISC 2013-10B MISC 2013-10
Now I am creating a query that shows the lifecycle of the order
MISC 2013-10 Issue and deadline date MISC 2013-10A issue and deadline date MISC 2013-10B issue and deadline date.I tried to create a query using self joins to the same table. SQL is attached
SELECT MISCORDER.OrderNum, MISCORDER.[Date Issued], MISCORDER.[Deadline Date], MISCORDER_1.OrderNum FROM MISCORDER LEFT JOIN MISCORDER AS MISCORDER_1 ON MISCORDER.OrderNum = MISCORDER_1.RescindedOrderID WHERE (((MISCORDER.OrderNum) Not Like '*A' And (MISCORDER.OrderNum) Not Like '*B' And (MISCORDER.OrderNum) Not Like '*C' And (MISCORDER.OrderNum) Not Like '*D') AND ((MISCORDER_1.OrderNum) Not Like '*B'));
How can I put a condition on the table to show only records with order num ending with A. It is not working if i use it in the where condition..