MySQL

2012-05-07 5 views
12

"पर खण्ड में अज्ञात स्तंभ" मैं है निम्नलिखित MySQL क्वेरी:MySQL

SELECT posts.id, posts.name, LEFT(posts.content, 400), posts.author, posts.date, users.display_name, 
    GROUP_CONCAT(tags.tag ORDER BY tag_linking.pid ASC SEPARATOR ",") update_tags 
FROM posts, tag_linking, tags 
INNER JOIN `users` 
ON posts.author=users.id; 
WHERE tag_linking.pid = posts.id 
    AND tags.id = tag_linking.tid 
ORDER BY posts.date DESC 

कौन सा,, था कि आप देख सकते तीन टेबल आदि आदि वैसे भी जोड़ता है, समस्या यह है कि यह एक त्रुटि देता है:

ERROR CODE: 
SQL Error (1054): Unknown column 'posts.author' in 'on clause' 

भले ही यह सरल एक और पृष्ठ पर इस्तेमाल क्वेरी काम करता है:

SELECT posts.id, posts.name, LEFT(posts.content, 400), posts.author, posts.date, users.display_name FROM `posts` 
INNER JOIN `users` 
ON posts.author=users.id 

किसी को क्यों इस OCC है के रूप में विचार है uring? आपकी सहायता के लिए धन्यवाद.

+1

किसी भी कारण से आप 'स्पष्ट शामिल' वाक्यविन्यास के साथ 'आलसी जुड़' मिश्रण कर रहे हैं? –

उत्तर

38

है अर्ध बृहदान्त्र क्योंकि आपके मिश्रण वाक्य रचना में शामिल होने

From Mysql[docs]

However, the precedence of the comma operator is less than of INNER JOIN, CROSS JOIN, LEFT JOIN, and so on. If you mix comma joins with the other join types when there is a join condition, an error of the form Unknown column 'col_name' in 'on clause' may occur. Information about dealing with this problem is given later in this section.

समाधान है:

To allow the join to be processed, group the first two tables explicitly with parentheses so that the operands for the ON clause are (t1,t2) and t3:

SELECT * FROM (t1, t2) JOIN t3 ON (t1.i1 = t3.i3);

Alternatively, avoid the use of the comma operator and use JOIN instead:

SELECT * FROM t1 JOIN t2 JOIN t3 ON (t1.i1 = t3.i3);

1

यह है कि आप ON posts.author=users.id;

+0

क्षमा करें, वह एक टाइपो था। –

0

अपने तालिकाओं के लिए एक उपनाम देते from खंड और परिवेश में उन्हें कोष्ठक के साथ जी इसे काम करेगा। लेकिन जुड़ने में मिश्रण अभी भी एक बुरा अभ्यास है।

0

यह बस कहता है कि लेखक पोस्ट टेबल में मौजूद नहीं है। या तो एक वर्तनी गलती ??