1

I am trying to get the union of a query and a view or a view and a view. But doing this in MySql gives back an ER_PARSE_ERROR.

So say I have a view called B_SAL for the state of a particular data set before a particular operation.

   CREATE OR REPLACE VIEW B_SAL AS 
       SELECT * FROM EMP ORDER BY EMP.COMM;

After that operation I want to get the UNION ALL of B_SAL and the current state of the data set, in this case EMP.

       (SELECT * FROM EMP ORDER BY EMP.COMM)
       UNION ALL
       B_SAL
Hakim
  • 452
  • 4
  • 15
  • Sample data and desired results would really help. A `union all` doesn't sounds like something useful. – Gordon Linoff May 06 '19 at 15:08
  • You do have to select from the view you can't just throw the view name in after the union. – P.Salmon May 06 '19 at 15:13
  • @GordonLinoff: Desired result depends heavily on the operation in between those two querys and another operation plus some sample data would make this question a bit too long and the question would lose focus. – Hakim May 06 '19 at 15:14

1 Answers1

1

You would need to select from that view, e.g.

SELECT * FROM EMP
UNION ALL
SELECT * FROM B_SAL;

But the above union is not good practice, because we are doing SELECT *, rather than explicitly listing out the columns we want to use. A better version would look something like this:

SELECT col1, col2, col3 FROM EMP
UNION ALL
SELECT col1, col2, col3 FROM B_SAL;
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360