Pergunta

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
  • I need to search by a part of the preference string and i need to have only 1 row into the result select query, which having all the preferences related ot the user as a text into a single record ?
Foi útil?

Solução

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. (http://www.firebirdsql.org/refdocs/langrefupd21-aggrfunc-list.html)

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... not sure if this actually works, but the direction should be the right one... Hope that helps!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top