If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > UNION problem, query's work alone but not in union

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-06-11, 18:50
RGM RGM is offline
Registered User
 
Join Date: Feb 2011
Posts: 29
UNION problem, query's work alone but not in union

Been at this for a while and getting no where.

Code:
(
SELECT fc.cause_id, fc.type_id, c.likes, fc.params, fc.activity_date, c.name, c.permalink 
FROM (SA_feeds_causes fc) 
JOIN SA_causes_followers cf ON cf.cause_id = fc.cause_id AND cf.angel_id = 3 
JOIN SA_causes c ON c.id = fc.cause_id 
)
UNION
(
SELECT ff.angel_id, ff.cause_id, ff.type_id, ff.params, ff.activity_date, c.name, c.permalink 
FROM (SA_feeds_friends ff) 
JOIN SA_angels_friends af ON af.friend_id = ff.angel_id AND af.angel_id = 3 AND af.state = "active" 
JOIN SA_causes c ON c.id = ff.cause_id 
)
ORDER BY 
activity_date desc
Separately the query's get what I expect but in a UNION I get:

Quote:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
'JOIN SA_angels_friends af ON af.friend_id = ff.angel_id AND af.angel_id = 3 AND ' at line 1
I've read that the number of cols need to match so added in one I don't really need, didn't fix.

Open to better ideas than union to do the same job too. I have a third table to add, not up to that yet however.
Reply With Quote
  #2 (permalink)  
Old 07-06-11, 20:39
RGM RGM is offline
Registered User
 
Join Date: Feb 2011
Posts: 29
Fuu. Removed parenthesis around the FROM's and it works.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On