Sqlite Query Error: Ambiguous Column Name?
I am running the following query on an sqlite3 database:
SELECT file.id AS fileID, file.path
FROM file
JOIN (SELECT tag_file_map.fileID,tag.tagname
FROM tag_file_map, tag JOIN tag ON tag_file_map.tagID = tag.id)
ON tag_file_map.fileID = file.id
WHERE tag.tagname = 'tag1' AND tag.tagname= 't开发者_Go百科ag2';
It gives me the following error: "ambiguous column name: tag.tagname"
Google seems to say that this error is produced when one or more tables share a column name and the specific table of the column is not specified. However, here, the table name IS specified. Plus, there is no other column with the name "tagname" in the entire database, so it shouldn't be ambiguous with or without the table name. Is this an sqlite problem, or is something off with my syntax?
on you inner select, change
FROM tag_file_map, tag JOIN tag on tag_file_map....
to
FROM tag_file_map JOIN tag on tag_file_map....
I think this will work...
SELECT file.id AS fileID, file.path
FROM file
JOIN
(SELECT tag_file_map.fileID, tag.tagname FROM tag_file_map
JOIN tag ON tag_file_map.tagID = tag.id
WHERE tag.tagname = 'tag1' AND tag.tagname= 'tag2')
ON tag_file_map.fileID = file.id;
精彩评论