Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2011
    Posts
    29

    Unanswered: 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:

    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.

  2. #2
    Join Date
    Feb 2011
    Posts
    29
    Fuu. Removed parenthesis around the FROM's and it works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •