Retrieve columns in multiple table where some columns are in both tables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aleach12
    New Member
    • Feb 2014
    • 2

    Retrieve columns in multiple table where some columns are in both tables

    I want retrieve columns x,y,z. Where x and y are in both tables A and B but z is only in table B. Any ideas? I keep getting x and y are ambiguous.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You need to show us your code.

    But that error means it doesn't know which x and which y you want. You need to qualify the table.

    Comment

    • aleach12
      New Member
      • Feb 2014
      • 2

      #3
      The code is simple
      SELECT x,y,z
      FROM A,B
      I tried UNION but that does not work since the data is too different.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        The problem is basically what I described in my first post. You need to qualify your tables. It doesn't know which table you want the x and y from. And if you want it from both tables, you need the include them twice, each qualified for the tables.

        Also, you're doing a cartesian join, are you sure you want to do that? that will multiply every row from one table with every row from the other table. You need to join the table on the key field to prevent that.

        If however you are looking to append the two separate sets of records together, then you need to use a UNION. You said it doesn't work because the data is too different. All you need to do then is make it the same by converting the data.

        Comment

        Working...