MySQL Workbench Error 1066

541 Views Asked by At

The following is what I'm working on for one of my query joins, I'm trying to create a table where the general screening details and combined with movie details. I keep getting the error 1066. Can anyone help or elaborate as to why?

SELECT  screening.ScreeningID, screening.MovieID, SeatCapacity, SeatsAvailable
    FROM screening
        LEFT JOIN movie
    ON screening.ID = movie.ScreeningID

    UNION 

SELECT MovieName, Director, Genre
    FROM movie     
        RIGHT JOIN movie
    ON screening.ID = movie.ScreeningID;

UPDATE:

Thanks guys for the replies, I have been an absolute complete noob and over complicated things (as usual). After some more digging around, this is what I came up with which perfectly works. I was trying to output the seating availability in a screening in one table by combining data from multiple tables.

SELECT s1.ScreeningID, s1.MovieID, s1.SeatCapacity, s1.SeatsAvailable, m1.Director, m1.MovieName, m1.Genre

FROM screening s1, movie m1

WHERE m1.screeningID = s1.screeningID

2

There are 2 best solutions below

0
On

You need to alias your tables and also each query that participates in the UNION must have the same number of columns.

0
On

Note: UNION is two complete (mostly unrelated) SELECT queries.

Your second query:

SELECT MovieName, Director, Genre
    FROM movie     
        RIGHT JOIN movie
    ON screening.ID = movie.ScreeningID;

Doesn't even have a table or alias called screening. (As well as column counts not matching for the UNION) It also has the table movie included twice, so every single column you access is going to be ambiguous and generate an error unless you use table aliases e.g.: FROM movie AS m1 etc.

I recommend starting by getting each separate query working by itself, only then combine them with a UNION statement.