<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
> <channel><title>Comments on: Conditional Joins in MySQL</title> <atom:link href="http://www.mysqldiary.com/conditional-joins-in-mysql/feed/" rel="self" type="application/rss+xml" /><link>http://www.mysqldiary.com/conditional-joins-in-mysql/</link> <description>Exploring, Sharing and  Discussing MySQL practice</description> <lastBuildDate>Thu, 02 Feb 2012 09:16:49 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: Rajitha</title><link>http://www.mysqldiary.com/conditional-joins-in-mysql/comment-page-1/#comment-3591</link> <dc:creator>Rajitha</dc:creator> <pubDate>Wed, 09 Nov 2011 18:42:58 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=71#comment-3591</guid> <description>Nice !!! Helpful!!!</description> <content:encoded><![CDATA[<p>Nice !!! Helpful!!!</p> ]]></content:encoded> </item> <item><title>By: Hazan Ilan</title><link>http://www.mysqldiary.com/conditional-joins-in-mysql/comment-page-1/#comment-3116</link> <dc:creator>Hazan Ilan</dc:creator> <pubDate>Thu, 24 Feb 2011 07:46:27 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=71#comment-3116</guid> <description>Hi Stefan,
I have fixed it.
Many thanks</description> <content:encoded><![CDATA[<p>Hi Stefan,<br
/> I have fixed it.<br
/> Many thanks</p> ]]></content:encoded> </item> <item><title>By: Stefan</title><link>http://www.mysqldiary.com/conditional-joins-in-mysql/comment-page-1/#comment-3115</link> <dc:creator>Stefan</dc:creator> <pubDate>Wed, 23 Feb 2011 17:15:53 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=71#comment-3115</guid> <description>Hi, thanks for the example.
Just to remark: the SQL Query has typing errors...
Following the correct code:
SELECT
q.q_id,
q.q_timestamp,
IF(q.q_is_answered, a.q_title, u.q_title) AS q_titleunanswered_questions_title
FROM
questions q
LEFT JOIN answered_questions_title a
ON (q.q_id = a.q_id AND q.q_is_answered = 1)
LEFT JOIN unanswered_questions_title u
ON (q.q_id = u.q_id AND q.q_is_answered = 0);
Greetings
Stefan</description> <content:encoded><![CDATA[<p>Hi, thanks for the example.<br
/> Just to remark: the SQL Query has typing errors&#8230;</p><p>Following the correct code:</p><p>SELECT<br
/> q.q_id,<br
/> q.q_timestamp,<br
/> IF(q.q_is_answered, a.q_title, u.q_title) AS q_titleunanswered_questions_title<br
/> FROM<br
/> questions q<br
/> LEFT JOIN answered_questions_title a<br
/> ON (q.q_id = a.q_id AND q.q_is_answered = 1)<br
/> LEFT JOIN unanswered_questions_title u<br
/> ON (q.q_id = u.q_id AND q.q_is_answered = 0);</p><p>Greetings</p><p>Stefan</p> ]]></content:encoded> </item> <item><title>By: Diego</title><link>http://www.mysqldiary.com/conditional-joins-in-mysql/comment-page-1/#comment-3008</link> <dc:creator>Diego</dc:creator> <pubDate>Thu, 27 Jan 2011 19:16:15 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=71#comment-3008</guid> <description>@Andrei, if you do understand that query as you formatted it... my most sincere congratulations: you are a genious. Just in case you don&#039;t know, linefeeds in sql queries do not affect the results. Not using linefeeds, on the other hand, does affect our braincells and our eyes.</description> <content:encoded><![CDATA[<p>@Andrei, if you do understand that query as you formatted it&#8230; my most sincere congratulations: you are a genious. Just in case you don&#8217;t know, linefeeds in sql queries do not affect the results. Not using linefeeds, on the other hand, does affect our braincells and our eyes.</p> ]]></content:encoded> </item> <item><title>By: Hazan Ilan</title><link>http://www.mysqldiary.com/conditional-joins-in-mysql/comment-page-1/#comment-2773</link> <dc:creator>Hazan Ilan</dc:creator> <pubDate>Mon, 10 Jan 2011 22:25:59 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=71#comment-2773</guid> <description>Andrei,
Use the left join that I mentioned in the post. It will allow you to include more than one column to the result.</description> <content:encoded><![CDATA[<p>Andrei,<br
/> Use the left join that I mentioned in the post. It will allow you to include more than one column to the result.</p> ]]></content:encoded> </item> <item><title>By: Hazan Ilan</title><link>http://www.mysqldiary.com/conditional-joins-in-mysql/comment-page-1/#comment-2772</link> <dc:creator>Hazan Ilan</dc:creator> <pubDate>Mon, 10 Jan 2011 22:22:20 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=71#comment-2772</guid> <description>John,
Your selects statements in the If Clause should return only one result and not three.</description> <content:encoded><![CDATA[<p>John,<br
/> Your selects statements in the If Clause should return only one result and not three.</p> ]]></content:encoded> </item> <item><title>By: John 5th</title><link>http://www.mysqldiary.com/conditional-joins-in-mysql/comment-page-1/#comment-2769</link> <dc:creator>John 5th</dc:creator> <pubDate>Thu, 06 Jan 2011 20:06:29 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=71#comment-2769</guid> <description>@Andrei
I have reformated you query but I guess it&#039;s not correct at all:
SELECT
journalists_replay.id AS replay_id,
journalists_replay.date AS replay_date,
journalists_replay.user_id AS user_id,
journalists_replay.user_type AS user_type,
journalists_replay.text AS replay_text,
IF (
journalists_replay.user_type = ’journalists’,
SELECT(
CONCAT_WS(‘ ‘, TRIM(journalists.name), TRIM(journalists.surname)) as user_name,
journalists.photo as user_photo,
journalists.posts as user_posts
WHERE
journalists_replay.user_id = jounalists.id
,
SELECT (
CONCAT_WS(‘ ‘, TRIM(prs.name), TRIM(prs.surname)) as user_name,
prs.photo as user_photo,
prs.posts as user_posts )
FROM
journalists_replay
WHERE
journalists_replay.post_id = ’69′ AND journalists_replay.enabled
ORDER BY
journalists_replay.date DESC;</description> <content:encoded><![CDATA[<p>@Andrei<br
/> I have reformated you query but I guess it&#8217;s not correct at all:</p><p>SELECT<br
/> journalists_replay.id AS replay_id,<br
/> journalists_replay.date AS replay_date,<br
/> journalists_replay.user_id AS user_id,<br
/> journalists_replay.user_type AS user_type,<br
/> journalists_replay.text AS replay_text,<br
/> IF (<br
/> journalists_replay.user_type = ’journalists’,</p><p> SELECT(<br
/> CONCAT_WS(‘ ‘, TRIM(journalists.name), TRIM(journalists.surname)) as user_name,<br
/> journalists.photo as user_photo,<br
/> journalists.posts as user_posts</p><p> WHERE<br
/> journalists_replay.user_id = jounalists.id</p><p> ,</p><p> SELECT (<br
/> CONCAT_WS(‘ ‘, TRIM(prs.name), TRIM(prs.surname)) as user_name,<br
/> prs.photo as user_photo,<br
/> prs.posts as user_posts )</p><p> FROM<br
/> journalists_replay</p><p> WHERE<br
/> journalists_replay.post_id = ’69′ AND journalists_replay.enabled</p><p>ORDER BY<br
/> journalists_replay.date DESC;</p> ]]></content:encoded> </item> <item><title>By: Andrei</title><link>http://www.mysqldiary.com/conditional-joins-in-mysql/comment-page-1/#comment-425</link> <dc:creator>Andrei</dc:creator> <pubDate>Sun, 07 Mar 2010 23:31:00 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=71#comment-425</guid> <description>This case is not a solution for followed query:
SELECT journalists_replay.id AS replay_id, journalists_replay.date AS replay_date, journalists_replay.user_id AS user_id, journalists_replay.user_type AS user_type, journalists_replay.text AS replay_text, IF(journalists_replay.user_type=&#039;journalists&#039;, SELECT(CONCAT_WS(&#039; &#039;, TRIM(journalists.name), TRIM(journalists.surname)) as user_name, journalists.photo as user_photo, journalists.posts as user_posts WHERE journalists_replay.user_id = jounalists.id, SELECT(CONCAT_WS(&#039; &#039;, TRIM(prs.name), TRIM(prs.surname)) as user_name, prs.photo as user_photo, prs.posts as user_posts) FROM journalists_replay WHERE journalists_replay.post_id = &#039;69&#039; AND journalists_replay.enabled ORDER BY journalists_replay.date DESC;
I can&#039;t find a solution for this.
Best regards.</description> <content:encoded><![CDATA[<p>This case is not a solution for followed query:</p><p>SELECT journalists_replay.id AS replay_id, journalists_replay.date AS replay_date, journalists_replay.user_id AS user_id, journalists_replay.user_type AS user_type, journalists_replay.text AS replay_text, IF(journalists_replay.user_type=&#8217;journalists&#8217;, SELECT(CONCAT_WS(&#8216; &#8216;, TRIM(journalists.name), TRIM(journalists.surname)) as user_name, journalists.photo as user_photo, journalists.posts as user_posts WHERE journalists_replay.user_id = jounalists.id, SELECT(CONCAT_WS(&#8216; &#8216;, TRIM(prs.name), TRIM(prs.surname)) as user_name, prs.photo as user_photo, prs.posts as user_posts) FROM journalists_replay WHERE journalists_replay.post_id = &#8217;69&#8242; AND journalists_replay.enabled ORDER BY journalists_replay.date DESC;</p><p>I can&#8217;t find a solution for this.<br
/> Best regards.</p> ]]></content:encoded> </item> <item><title>By: Ben</title><link>http://www.mysqldiary.com/conditional-joins-in-mysql/comment-page-1/#comment-362</link> <dc:creator>Ben</dc:creator> <pubDate>Thu, 25 Feb 2010 09:20:20 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=71#comment-362</guid> <description>Consider using subqueries:
SELECT
q_id,
q_timestamp,
IF(q_is_answered,
SELECT q_title FROM answered_questions WHERE q_id=q.q_id,
SELECT q_title FROM unanswered_questions WHERE q_id=q.q_id) as q_title
FROM
questions q
I believe this is clearer, shorter and will run faster.
(It also assumes that each of the subqueries will return a single value.
The original solution does not handle this situation well either.)</description> <content:encoded><![CDATA[<p>Consider using subqueries:</p><p>SELECT<br
/> q_id,<br
/> q_timestamp,<br
/> IF(q_is_answered,<br
/> SELECT q_title FROM answered_questions WHERE q_id=q.q_id,<br
/> SELECT q_title FROM unanswered_questions WHERE q_id=q.q_id) as q_title<br
/> FROM<br
/> questions q</p><p>I believe this is clearer, shorter and will run faster.<br
/> (It also assumes that each of the subqueries will return a single value.<br
/> The original solution does not handle this situation well either.)</p> ]]></content:encoded> </item> </channel> </rss>
