Jump to content

[SOLVED] problem when simulating FULL JOIN and grouping


vintox

Recommended Posts

I am trying to make a full join query

i found some simulating methods for simulating full join

but when i am using simulating and the selection is a grouping value like count()

i am getting a syntax error

 

the query is going like this:

SELECT p.*,COUNT(reply) as rcount 
	FROM reply r
		LEFT OUTER JOIN posts p
			ON p.id = r.post GROUP BY r.post
UNION
SELECT p.*,COUNT(reply) as rcount 
	FROM reply r
		RIGHT OUTER JOIN posts p
			ON p.id = r.post GROUP BY r.post
WHERE COUNT(reply) IS NULL

 

Thanks in advance

vintox

Link to comment
Share on other sites

I don't get your SQL.

 

1. You're counting a table name? I'm referring to COUNT(reply). Isn't reply the table name?

2. Why are you using UNION on the same SQL?

3. WHERE COUNT(reply) IS NULL? What? ??? I don't think COUNT(reply) will ever be NULL. I can be 0. And change COUNT(reply) to rcount.

Link to comment
Share on other sites

1.In reply table the is a reply field

2.I am using UNION on the same SQL because Mysql doesn't have an option of using FULL OUTER JOIN

 

3.even if i use WHERE rcount=0 or trying COUNT(reply)=0 i get syntax error

Link to comment
Share on other sites

Each query in UNION is in fact a separate query. If you want to use WHERE with UNION results, you have to use subquery

 

SELECT *
FROM
(
query1
UNION
query2
) AS subQuery
WHERE ...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.