0

So i wanted to extract information from 3 tables at the same time, but whenever i update my query on table1 it gives me duplicates and overrides the previous entries, like in row n in garage column if i update garage to red, it will display red for the previous entry as well. any thoughts on how to do this?

SELECT `date`,`tagid`,`garage`,`class` 
FROM table1 JOIN table2 ON table1.number = table2.tagid
UNION SELECT `date`,`tagid`,`garage`,`class` 
FROM table1 JOIN table3 ON table1.number = table3.tagid
2
  • 1
    please provide table structure and an exemple output Commented Aug 1, 2012 at 6:05
  • A UNION by definition removes all duplicates from your resultset so the statement you've presented can't possibly contain duplicates. Without additional information as asked by @PugganSe, we can only guess what it is you really want. The statement whenever I update my query on table1 it gives me duplicates ... like in row n doesn't make any sense to me. Commented Aug 1, 2012 at 6:33

1 Answer 1

1

It looks like you want to do somthing like:

SELECT date, tagid, garage, class 
FROM table1 
LEFT JOIN (
    SELECT date, tagid, garage, class FROM table2 
    UNION
    SELECT date, tagid, garage, class FROM table3 
) AS table_2_and_3 ON (table1.number = table_2_and_3.tagid)

you may need to remove some fields on row 4 and 6 if they are in table 1.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.