Welcome Guest, Not a member yet? Register   Sign In
[Solved] Problem with an UNION query
#1

[eluser]Kromack[/eluser]
Version : CI 1.6.1

Hi all,

I have a problem with one query that produce a strange error...

Here is my code :

Code:
public function getListeAbonnes()
{
   $sql = "SELECT courriel FROM Prospect WHERE estActif = '1' UNION SELECT courriel FROM ProspectChaudParticulier WHERE estActif='1' AND recevoirInformation = '1' AND recevoirPromotion = '1'";
   $this->db->query($sql);
            
   return $this->db->get();

}

And i have this error :

Code:
An Error Was Encountered
Error Number: 1096

No tables used

SELECT *

But I'm a little confused because this query work properly when I run it with phpmyadmin or in CLI.

Does anybody have an idea ?
Is there an active-record way to do UNION query ?

What I'm missing ? ^^
#2

[eluser]gtech[/eluser]
I think that $this->db->query actually runs the query as well, so you dont need the $this->db->get(). As the query has already been run $this->db->get() will be blank and I am guessing that is why you see the SELECT * error.

try this code:

Code:
public function getListeAbonnes()
{
   $sql = "SELECT courriel FROM Prospect WHERE estActif = '1' UNION SELECT courriel FROM ProspectChaudParticulier WHERE estActif='1' AND recevoirInformation = '1' AND recevoirPromotion = '1'";
   $query = $this->db->query($sql);
   return $query;

}
#3

[eluser]Kromack[/eluser]
You're righ, stupid error from me.

Thank you for your help.




Theme © iAndrew 2016 - Forum software by © MyBB