sqlfirebird2.5

One result from join between 2 tables?


It is a bit complicated to explain into the main caption, but the situation is as follow : - I have 2 tables : Users, Preferences.

defined as follow

Users :

ID | NAME | FK_NODE_PREFERENCES

Preferences :

ID | FK_USERS | PREFERENCE_DESCRIPTION

the idea is to have alot of preferences for each user...

the results shall look as follow :

USER | ALL_PREFERENCES

Solution

  • I'm not familiar with Firebird, but it seems to have a LIST() function which should be an equivalent to the GROUP_CONCAT() function in MySQL. (see documentation of LIST())

    So, basically the query should look something like this:

    SELECT Users.name, LIST(Preferences.preference_description, ' ') AS ALL_PREFERENCES FROM Users JOIN NodePreferences ON Users.fk_node_preferences = Preferences.id WHERE Preferences.preference_description LIKE '%abc%' GROUP BY Users.name
    

    So, I'm not sure if this actually works, but the direction should be the right one.