Mysql-Pendant zu Postgres SELECT ARRAY – SELFHTML-Forum Forum als Ergänzung zum SELFHTML-Wiki und zur Dokumentation SELFHTML https://forum.selfhtml.org/self Mysql-Pendant zu Postgres SELECT ARRAY Fri, 20 Dec 13 14:57:13 Z https://forum.selfhtml.org/self/2013/dec/20/mysql-pendant-zu-postgres-select-array/1597392#m1597392 https://forum.selfhtml.org/self/2013/dec/20/mysql-pendant-zu-postgres-select-array/1597392#m1597392 <p>Hallo allerseits,</p> <p>im Postgresql gibts ja den Aufruf SELECT ARRAY(SELECT id From table). Ergebnis ist in dem Fall ein kommagetrennter String mit allen Ids also {5,7,9}.<br> Gibt es dafür auch in Mysql in dem Fall 5.5 ein Pendant dafür? Google und Forensuche hab ich nix gefunden. Danke schonmal.</p> <p>Mit freundlichen Grüßen<br> xpfreund</p> Mysql-Pendant zu Postgres SELECT ARRAY Fri, 20 Dec 13 16:20:08 Z https://forum.selfhtml.org/self/2013/dec/20/mysql-pendant-zu-postgres-select-array/1597393#m1597393 https://forum.selfhtml.org/self/2013/dec/20/mysql-pendant-zu-postgres-select-array/1597393#m1597393 <p>Meine Herren!</p> <blockquote> <p>im Postgresql gibts ja den Aufruf SELECT ARRAY(SELECT id From table). Ergebnis ist in dem Fall ein kommagetrennter String mit allen Ids also {5,7,9}.<br> Gibt es dafür auch in Mysql in dem Fall 5.5 ein Pendant dafür? Google und Forensuche hab ich nix gefunden. Danke schonmal.</p> </blockquote> <p>Ohne PostgreSQL zu kennen: Eine komma-separierte Liste kannst du mit <a href="http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat" rel="nofollow noopener noreferrer">GROUP_CONCAT</a> zusammen bauen, die umschließenden geschweiften Klammern mit <a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat" rel="nofollow noopener noreferrer">CONCAT</a>.</p> Mysql-Pendant zu Postgres SELECT ARRAY Fri, 20 Dec 13 16:41:25 Z https://forum.selfhtml.org/self/2013/dec/20/mysql-pendant-zu-postgres-select-array/1597394#m1597394 https://forum.selfhtml.org/self/2013/dec/20/mysql-pendant-zu-postgres-select-array/1597394#m1597394 <p>Hallo,</p> <p>scheint nicht so zu funktionieren wie es soll.<br> Nochmal ein detailierteres Bsp.:<br> SELECT id, ARRAY(SELECT id FROM table2 where table1.id = table2.idtbl1) FROM table1 where id = 1</p> <p>Ergebnis:<br> 5, {7,9,11}<br> Vom Prinzip her ein left join auf tabelle2 mit dem Unterschied, dass nicht 3 Ergebnisse, sondern nur eines kommt</p> <blockquote> <p>Meine Herren!</p> <blockquote> <p>im Postgresql gibts ja den Aufruf SELECT ARRAY(SELECT id From table). Ergebnis ist in dem Fall ein kommagetrennter String mit allen Ids also {5,7,9}.<br> Gibt es dafür auch in Mysql in dem Fall 5.5 ein Pendant dafür? Google und Forensuche hab ich nix gefunden. Danke schonmal.</p> </blockquote> <p>Ohne PostgreSQL zu kennen: Eine komma-separierte Liste kannst du mit <a href="http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat" rel="nofollow noopener noreferrer">GROUP_CONCAT</a> zusammen bauen, die umschließenden geschweiften Klammern mit <a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat" rel="nofollow noopener noreferrer">CONCAT</a>.</p> </blockquote> <p>gruß aus Berlin</p> Mysql-Pendant zu Postgres SELECT ARRAY Fri, 20 Dec 13 16:45:55 Z https://forum.selfhtml.org/self/2013/dec/20/mysql-pendant-zu-postgres-select-array/1597395#m1597395 https://forum.selfhtml.org/self/2013/dec/20/mysql-pendant-zu-postgres-select-array/1597395#m1597395 <p>Meine Herren!</p> <blockquote> <p>scheint nicht so zu funktionieren wie es soll.</p> </blockquote> <p>Wie sieht denn dein Code aus, analog zu dem gerade gegebenen Beispiel?</p> Mysql-Pendant zu Postgres SELECT ARRAY Fri, 20 Dec 13 17:53:08 Z https://forum.selfhtml.org/self/2013/dec/20/mysql-pendant-zu-postgres-select-array/1597396#m1597396 https://forum.selfhtml.org/self/2013/dec/20/mysql-pendant-zu-postgres-select-array/1597396#m1597396 <p>Hallo,</p> <p>meine Idee war jetzt</p> <p>SELECT <code>table1</code>.id, GROUP_CONCAT(SELECT id FROM <code>table2</code> WHERE <code>table2</code>.tbl1id = <code>table1</code>.id) as 'ids' FROM <code>table1</code> WHERE id = 5</p> <p>aber das gibt nen schönen Fehler, da das Group_concat anscheinend kein select an nimmt</p> <blockquote> <p>Meine Herren!</p> <blockquote> <p>scheint nicht so zu funktionieren wie es soll.</p> </blockquote> <p>Wie sieht denn dein Code aus, analog zu dem gerade gegebenen Beispiel?</p> </blockquote> <p>gruß aus Berlin</p> Mysql-Pendant zu Postgres SELECT ARRAY Sat, 21 Dec 13 12:06:18 Z https://forum.selfhtml.org/self/2013/dec/20/mysql-pendant-zu-postgres-select-array/1597397#m1597397 https://forum.selfhtml.org/self/2013/dec/20/mysql-pendant-zu-postgres-select-array/1597397#m1597397 <p>Hi,</p> <blockquote> <p>meine Idee war jetzt</p> <p>SELECT <code>table1</code>.id, GROUP_CONCAT(SELECT id FROM <code>table2</code> WHERE <code>table2</code>.tbl1id = <code>table1</code>.id) as 'ids' FROM <code>table1</code> WHERE id = 5</p> <p>aber das gibt nen schönen Fehler, da das Group_concat anscheinend kein select an nimmt</p> </blockquote> <p>Nur ja keinen Blick ins MySQL-Handbuch werfen, sonst könnte man ja lesen, daß GROUP_CONCAT im Zusammenhang mit GROUP BY stehen könnte ...</p> <p>cu,<br> Andreas</p> <div class="signature">-- <br> <a href="http://MudGuard.de/" rel="nofollow noopener noreferrer">Warum nennt sich Andreas hier MudGuard?</a><br> <a href="http://ostereier.andreas-waechter.de/" rel="nofollow noopener noreferrer">O o ostern ...</a><br> Fachfragen per Mail sind frech, werden ignoriert. Das Forum existiert.<br> </div>