2013-10-02 36 views
0

MySQL查詢與下面的SQL與工會,並在第

SELECT societa.nome, documenti.document, soieditor.nominativo, document_revision.* 
FROM document_revision 
     JOIN societa ON societa.id = document_revision.societa 
     JOIN documenti ON documenti.id = document_revision.tipo_document 
     JOIN soieditor ON soieditor.id = document_revision.createdby 
     WHERE document_revision.id in(
     (
    (SELECT id from document_revision WHERE `description` LIKE '%f%' OR `tag` LIKE '%f%' OR `lingua` LIKE '%f%') 
    union 
    (SELECT doc_rev_id from document_metadata WHERE `met_key` LIKE '%f%' OR `meta_value` LIKE '%f%') 
    union 
    (SELECT doc_id from document_files WHERE `file_name` LIKE '%f%'))) 

搜索MySQL錯誤給了我下面的錯誤「#1064 - 你在你的SQL語法錯誤;檢查對應於你的MySQL服務器版本使用附近的正確語法手冊%fwdfdfdfd‘第1行'

請幫我麻煩射擊誤差工會(從document_metadata WHERE met_key LIKE選擇doc_rev_id’。

回答

1
SELECT societa.nome, 
    documenti.document, 
    soieditor.nominativo, 
    document_revision.* 
FROM document_revision 
    JOIN societa ON societa.id = document_revision.societa 
    JOIN documenti ON documenti.id = document_revision.tipo_document 
    JOIN soieditor ON soieditor.id = document_revision.createdby 
WHERE document_revision.id in 
(
    SELECT id as ii 
    from document_revision 
    WHERE description LIKE '%f%' OR tag LIKE '%f%' OR lingua LIKE '%f%' 

    union 

    SELECT doc_rev_id as ii 
    from document_metadata 
    WHERE met_key LIKE '%f%' OR meta_value LIKE '%f%' 

    union 

    SELECT doc_id as ii 
    from document_files 
    WHERE `file_name` LIKE '%f%' 
) 
0

嘗試把一個別名對你的工會鏈的第一子查詢,以這樣的方式

SELECT societa.nome, documenti.document, soieditor.nominativo, document_revision.* 
FROM document_revision 
JOIN societa ON societa.id = document_revision.societa 
JOIN documenti ON documenti.id = document_revision.tipo_document 
JOIN soieditor ON soieditor.id = document_revision.createdby 
WHERE document_revision.id in(
(
    (SELECT id as myid -- alias named your output field 
    from document_revision 
    WHERE `description` LIKE '%f%' OR `tag` LIKE '%f%' OR `lingua` LIKE '%f%') 
    union 
    (SELECT doc_rev_id 
    from document_metadata WHERE `met_key` LIKE '%f%' OR `meta_value` LIKE '%f%') 
    union 
    (SELECT doc_id from document_files WHERE `file_name` LIKE '%f%') 
) 
)