Results 1 to 7 of 7

Thread: SQL in Access Query

  1. #1

    Thread Starter
    Hyperactive Member richy's Avatar
    Join Date
    Jan 1999
    Location
    Liverpool, England
    Posts
    353

    SQL in Access Query

    I want to select information from two tables that are identical (one as current information and one has archived information)

    Table1
    T1Key
    T1Name

    Table2
    T2Key
    T2Name

    Is there anyway of doing a SQL statement to select all information from both tables? Obviously it's not a time for an inner join as they aren't connected.
    ASP, PHP, VB, JavaScript, CSS, HTML, a little C and a little CGI.

    Richard Whitehouse.
    Join the Footie Predictions League


    "Make it idiot proof and someone will make a better idiot."

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: SQL in Access Query

    select * from table1, table2

  3. #3

    Thread Starter
    Hyperactive Member richy's Avatar
    Join Date
    Jan 1999
    Location
    Liverpool, England
    Posts
    353

    Re: SQL in Access Query

    I've tried that but it doesn't select anything and instead brings back the following format

    Table1.T1Key Table1.T1Name, Table2.T2Key, Table2.T2Name in one row

    rather than

    Table1Item
    Table1Item
    Table1Item
    Table2Item

    if that makes any sense.
    ASP, PHP, VB, JavaScript, CSS, HTML, a little C and a little CGI.

    Richard Whitehouse.
    Join the Footie Predictions League


    "Make it idiot proof and someone will make a better idiot."

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: SQL in Access Query

    You need to do a UNION Query
    Code:
    SELECT T1Key ,T1Name FROM Table1
    UNION ALL
    SELECT T2Key ,T2Name FROM Table2
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  5. #5

    Thread Starter
    Hyperactive Member richy's Avatar
    Join Date
    Jan 1999
    Location
    Liverpool, England
    Posts
    353

    Re: SQL in Access Query

    Thats great. Thanks.

    Is there anyway of grouping them together, so if there are two values of for example T1Name being the same then summing up the keys?

    I know there is no reason of summing keys, but it keeps things simple using the same column names I've already mentioned.
    ASP, PHP, VB, JavaScript, CSS, HTML, a little C and a little CGI.

    Richard Whitehouse.
    Join the Footie Predictions League


    "Make it idiot proof and someone will make a better idiot."

  6. #6
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: SQL in Access Query

    Use a SELECT DISTINCT instead of just a SELECT to get unique values.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: SQL in Access Query

    If I understood correctly, then this should get what you want:
    Code:
    SELECT TName, Sum(TKey)
    FROM
      (SELECT T1Key as TKey, T1Name as TName FROM Table1
       UNION ALL
       SELECT T2Key as TKey, T2Name as TName FROM Table2)
    GROUP BY TName

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width