1

I have all kinds of views in mysql with employee data. I have tried to use methods like this -https://stackoverflow.com/questions/2384298/why-does-mysql-report-a-syntax-error-on-full-outer-join but they simply don't work for views.

I end up getting more of a LEFT JOIN as a result. Is there a way to merge two views without including duplicates in mysql - I am currently using a 4 view process to duplicate this.

asked May 14, 2015 at 19:44
3
  • Full joining 2 views is no different than full joining 2 tables. Shows us what you tried. Commented May 14, 2015 at 19:54
  • @ypercube - I did exactly what was in the link. I got all of the entries that weren't matches. I have tried unions and group bys but I have to run them over several views to get them to work. I can get it working but not in one view statement. I want to know how I can take viewA and add viewB (and ViewC and ViewD...) where there are no duplicate ids. Commented May 14, 2015 at 20:08
  • Did you try the answer there with 3 views/tables? I think that answer is wrong when it comes to 3+ tables. Edit the question and add the SHOW CREATE VIEW viewname; output. Commented May 14, 2015 at 20:12

1 Answer 1

1

Simulation of FULL OUTER JOIN:

( SELECT ... FROM a LEFT JOIN b ON ... ) -- Intersection, plus rest of b
UNION ALL -- There will be no overlap; ALL is faster
( SELECT ... FROM b LEFT JOIN a ON ... WHERE a.id IS NULL ) -- Just rest of a

(The link given is less efficient because it gets the Intersection twice, then dedups by doing UNION DISTINCT.)

If you need a FULL OUTER JOIN between more than 2 tables, then it gets messier. (But you did not ask for that.)

answered May 14, 2015 at 21:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.