tags:

views:

294

answers:

2

Given the query:

SELECT
 DISTINCT score.*
FROM score
LEFT OUTER JOIN tag ON (tag.id_score = score.id)
INNER JOIN score AS score_1 USING (id)
WHERE
 (score.song_name LIKE '%[Upload]%' 
  OR score.artist_name LIKE '%[Upload]%' 
  OR score.creator_name LIKE '%[Upload]%' 
  OR tag.name LIKE '%[Upload]%')
 AND (score_1.song_name LIKE '%[Check OK]%' 
  OR score_1.artist_name LIKE '%[Check OK]%' 
  OR score_1.creator_name LIKE '%[Check OK]%' 
  OR tag.name LIKE '%[Check OK]%')

I get Column 'id' in from clause is ambiguous in MySQL 5.1.37. Usually people fix this by adding an explicit table in front of their ambiguous columns, but here I've already did so: (tag.id_score = score.id). Leaving the LEFT OUTER JOIN tag fixes the problem, but doesn't allow searching inside tags table.

Is this a bug in MySQL or I've missed something?

+2  A: 

Will it not help if you change

INNER JOIN score AS score_1 USING (id)

to

INNER JOIN score AS score_1 (score_1.id_score = score.id)
astander
yes, INNER JOIN score AS score_1 ON (score_1.id = score.id)has removed the error message, but gave me no results. I think I need to use sub-queries/views and not join too many things together.
A: 

In this case I've used subqueries sucessfully like this:

SELECT * FROM ( SELECT
    DISTINCT score.*
FROM score
LEFT OUTER JOIN tag ON (tag.id_score = score.id)
WHERE
    (score.song_name LIKE '%[Upload]%' 
     OR score.artist_name LIKE '%[Upload]%' 
     OR score.creator_name LIKE '%[Upload]%' 
     OR tag.name LIKE '%[Upload]%')


) AS score_0 INNER JOIN ( SELECT
    DISTINCT score.*
FROM score
LEFT OUTER JOIN tag ON (tag.id_score = score.id)
WHERE
    (score.song_name LIKE '%[Check OK]%' 
     OR score.artist_name LIKE '%[Check OK]%' 
     OR score.creator_name LIKE '%[Check OK]%' 
     OR tag.name LIKE '%[Check OK]%')


) AS score_1 USING (id)