Welcome Guest, Not a member yet? Register   Sign In
Can't perform a UNION ALL MySQL query
#12

[eluser]David Johansson[/eluser]
[quote author="Ci beginner" date="1248724703"][quote author="Colin Williams" date="1248684219"]You need to tell the DB class to not protect identifiers by supplying a third param of TRUE.

Code:
$this->db->where('UNION ALL "
        SELECT * FROM `blog` ORDER BY `id` DESC
        UNION ALL
        SELECT COUNT(*) FROM blog_comentarios, blog WHERE blog_comentarios.post_id = blog.id"', NULL, TRUE);
[/quote]

Oops, bad news... I've tried the code:

Code:
$this->db->select('blog_comentarios.post_id, blog.id');
  $this->db->from('blog_comentarios, blog');
$this->db->where('UNION ALL "
  SELECT * FROM `blog` ORDER BY `id` DESC
  UNION ALL
  SELECT COUNT(*) FROM blog_comentarios, blog WHERE blog_comentarios.post_id = blog.id"', NULL, TRUE);  
  $data['query'] = $this->db->get();

And same error here:

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 'ALL " SELECT * FROM `blog` ORDER BY `id` DESC UNION ALL SELECT COUNT(*) FROM ' at line 3

SELECT `blog_comentarios`.`post_id`, `blog`.`id` FROM (`blog_comentarios`, `blog`) WHERE `UNION` ALL " SELECT * FROM `blog` ORDER BY `id` DESC UNION ALL SELECT COUNT(*) FROM blog_comentarios, blog WHERE blog_comentarios.post_id = blog.id"

What can I do? Thank you![/quote]

1: The third parameter must be false, not true.
2: Since active record is not that complicated it's probably better to use regular queries.
3: I don't think you should have the citation marks (") around the second query, maybe you should use brackets instead or it might even work without anything...


Messages In This Thread
Can't perform a UNION ALL MySQL query - by El Forum - 07-26-2009, 09:25 PM
Can't perform a UNION ALL MySQL query - by El Forum - 07-26-2009, 09:43 PM
Can't perform a UNION ALL MySQL query - by El Forum - 07-26-2009, 09:55 PM
Can't perform a UNION ALL MySQL query - by El Forum - 07-27-2009, 08:58 AM
Can't perform a UNION ALL MySQL query - by El Forum - 07-27-2009, 10:35 AM
Can't perform a UNION ALL MySQL query - by El Forum - 07-27-2009, 11:18 AM
Can't perform a UNION ALL MySQL query - by El Forum - 07-27-2009, 11:25 AM
Can't perform a UNION ALL MySQL query - by El Forum - 07-27-2009, 12:15 PM
Can't perform a UNION ALL MySQL query - by El Forum - 07-27-2009, 12:55 PM
Can't perform a UNION ALL MySQL query - by El Forum - 07-27-2009, 01:05 PM
Can't perform a UNION ALL MySQL query - by El Forum - 07-27-2009, 02:24 PM
Can't perform a UNION ALL MySQL query - by El Forum - 07-27-2009, 07:01 PM
Can't perform a UNION ALL MySQL query - by El Forum - 07-27-2009, 07:08 PM



Theme © iAndrew 2016 - Forum software by © MyBB