sqlmysqljoinmysql-error-1052

MySQL - Selecting data from multiple tables all with same structure but different data


Ok, here is my dilemma I have a database set up with about 5 tables all with the exact same data structure. The data is separated in this manner for localization purposes and to split up a total of about 4.5 million records.

A majority of the time only one table is needed and all is well. However, sometimes data is needed from 2 or more of the tables and it needs to be sorted by a user defined column. This is where I am having problems.

data columns:

id, band_name, song_name, album_name, genre

MySQL statment:

SELECT * from us_music, de_music where `genre` = 'punk'

MySQL spits out this error:

#1052 - Column 'genre' in where clause is ambiguous

Obviously, I am doing this wrong. Anyone care to shed some light on this for me?


Solution

  • I think you're looking for the UNION clause, a la

    (SELECT * from us_music where `genre` = 'punk')
    UNION
    (SELECT * from de_music where `genre` = 'punk')