CodeIgniter Forums
Problem with a db query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Problem with a db query (/showthread.php?tid=7497)



Problem with a db query - El Forum - 04-11-2008

[eluser]Unknown[/eluser]
I have a problem with one query.

I have this code:

Code:
$this->db->select("f.*, (SELECT GROUP_CONCAT (CONCAT(p.nome, ' ', p.cognome) SEPARATOR ', ')
                         FROM professionisti p
                                                 WHERE p.id IN (SELECT r.id_professionista FROM registi r WHERE r.id_film = f.id)
                                                ) AS regista", FALSE);
$this->db->from($this->tables['film'] . ' f');
$this->db->where("f.pagina_html = '" . $film . "'");
$sql = $this->db->get();
return $sql->row();

but the above code return me the following error:

Quote:An Error Was Encountered

Error Number: 1064

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 'SEPARATOR ', ') FROM professionisti p ' at line 1

SELECT f.*, (SELECT GROUP_CONCAT (CONCAT(p.nome, ' ', p.cognome) SEPARATOR ', ') FROM professionisti p WHERE p.id IN (SELECT r.id_professionista FROM registi r WHERE r.id_film = f.id) ) AS regista FROM (`film` f) WHERE f.pagina_html = 'grindhouse_us_version'

the query reported in the error message don't have problem in phpmyadmin.

I also tried with the following code:

Code:
$sql = "SELECT f.*, (SELECT GROUP_CONCAT (CONCAT(p.nome, ' ', p.cognome) SEPARATOR ', ')
FROM professionisti p
WHERE p.id IN (SELECT r.id_professionista FROM registi r WHERE r.id_film = f.id)
) AS regista
FROM film f
WHERE f.pagina_html = '" . $film . "'";
$query = $this->db->query($sql);

but return me the same error.

Where is the problem?


PS: excuse me for my english. I hope you can understand what i wrote.


Problem with a db query - El Forum - 04-11-2008

[eluser]Unknown[/eluser]
Ok, i have found the solution.

The problem was the blank space between "GROUP_CONCAT" and "(". When i leave that space it's ok.