Results 1 to 8 of 8
  1. #1
    Pells is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    25

    Referencing fields from tables


    Is it possible to reference a field from another table that you dont have directly linked into your query?

    I am using code to select fields from table 1, but also using the NOT EXISTS code to reference another table to have the results of where data doesn's exist in table 2 and I would like to have a couple of the fields in table 2 shown in my queried results.

    If this doesn't make sense, please let me know and I will try to explain better (if I can).

    Many thanks for any suggestions.

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    It looks like doesn't make sense.
    You are getting record from table1 without match in table2, but you want some fields from table2. since there is not match, you can get nothing from table2.

  3. #3
    Pells is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    25
    Quote Originally Posted by weekend00 View Post
    It looks like doesn't make sense.
    You are getting record from table1 without match in table2, but you want some fields from table2. since there is not match, you can get nothing from table2.
    Many thanks weekend00.

    Didnt think it made too much sense!

    I have a query that looks for the absence of data in a table using NOT EXISTS SQL code that looks to see if a record exists and if not, shows the resulting fields from another table - this is fine and perfect for what I am trying to achieve but I would like to show a couple of the field names that is in a table that isn't directly shown in the query window but is referenced via the code in the query.

    Here is an article that details the NOT EXISTS function that I have used:

    http://www.devx.com/dbzone/Article/9570/1954

    Hope this makes more sense, if not, I could post my code and try to explain again?

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    an example with explainations will be much more clear.
    such as sample data in you table 1 and 2, and the result that you are expecting.

  5. #5
    Pells is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    25
    Quote Originally Posted by weekend00 View Post
    an example with explainations will be much more clear.
    such as sample data in you table 1 and 2, and the result that you are expecting.
    Table 1:
    Personnel_Nr i.e. 12345, 11111, 22222
    Surname i.e. Smith, Jones, Harris

    Table 2:
    Personnel_Nr i.e. 12345, 11111, 22222
    Week_No i.e. 41, 41, 42

    My query looks to find where there are no records against a specific week_no for personnel_nr's. If there are no records in table 2 week_nr, then return the personnel_nr from table 1.

    So based on the above, my query would return for Week 41:

    Personnel_Nr = 22222
    Surname = Harris

    The query works fine, but I would like to show the week_nr from table 2 in the results by amending my code that consists of NOT EXIST to provide me with the absence of data, so it would look like this:

    Personnel_Nr = 22222
    Surname = Harris
    Week_Nr = 41

    Hope this helps.

  6. #6
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    If you mean that you will provide specified week number to get the result, why not just put it in the result that you got:

    for example, when you specify week no 41, you get 22222, Harris, then you just add 41.

    Following query is just for reference:

    select [input_week_no],table1.* from table1 left join table2 on table1.personal_NR=table1.personal_nr where table2.personal_nr is null where table2.week_no=[input_week_no]

    when you run this query, it asks for input_week_n.

  7. #7
    Pells is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    25
    Quote Originally Posted by weekend00 View Post
    If you mean that you will provide specified week number to get the result, why not just put it in the result that you got:

    for example, when you specify week no 41, you get 22222, Harris, then you just add 41.

    Following query is just for reference:

    select [input_week_no],table1.* from table1 left join table2 on table1.personal_NR=table1.personal_nr where table2.personal_nr is null where table2.week_no=[input_week_no]

    when you run this query, it asks for input_week_n.
    Many thanks for your suggestion, but no, this isnt what I am looking for. I want to add the field name week_nr to my query results but this field doesn't exist in table 1 but table 2.

    Thanks for your help.

  8. #8
    Pells is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    25
    Many thanks for all your suggestions, I think I have managed to solve this one.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Combine two unrelated tables with the same fields
    By lghovden06 in forum Queries
    Replies: 4
    Last Post: 07-27-2010, 03:36 PM
  2. Load tables name and fields name to list box
    By casseopia00 in forum Programming
    Replies: 1
    Last Post: 06-30-2009, 10:09 PM
  3. Replies: 1
    Last Post: 03-31-2009, 09:03 AM
  4. Replies: 0
    Last Post: 03-05-2007, 08:04 PM
  5. Replies: 1
    Last Post: 06-03-2006, 05:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums