0

I want to display all related information in to the same row column. Currently my output and query are the following:

Trader Items
Prapor Weapons
Prapor Wearables
Prapor Weapon Modifications
Prapor Health and Buffs
Therapist Weapons
Therapist Wearables
Therapist Weapon Modifications
Therapist Health and Buffs
select NPC_Traders.Nickname as Trader, Classes.Class as Items
from NPC_Traders, Classes
where Items IN (
           select npc.Tradeables
           from NPC_Traders npc 
           where npc.Tradeables LIKE '%1%' OR
                 npc.Tradeables LIKE '%2%' OR
                 npc.Tradeables LIKE '%3%' OR
                                npc.Tradeables LIKE '%4%');

I want to display the information such as:

Trader Items
Prapor Weapons, Wearables, Weapon Modifications, Health and Buffs
Therapist Weapons, Wearables, Weapon Modifications, Health and Buffs

Is there a technique I can use to solve this issue?

4
  • Hi, and welcome to the forum! We really need to know what your server is - this kind of functionality is frequently dependent on various "tricks" from the server provider! Dec 9 '20 at 7:38
  • Sorry about that, I'm using Sqlite3
    – zepher4
    Dec 9 '20 at 8:38
  • sqlite.org/lang_aggfunc.html GROUP_CONCAT()
    – Akina
    Dec 9 '20 at 9:17
  • Me again! I should have mentioned this in the first post - can you please provide your tables as DDL (CREATE TABLE...) and your data as DML (INSERT INTO...) - it helps those who are trying to help you! Even better, do this as a fiddle, but be sure to include what's in the fiddle here also! Dec 9 '20 at 11:14
0

You can apply the GROUP_CONCAT function on top of your existing query like so:

SELECT Trader, GROUP_CONCAT(Items, ',') AS Items
FROM 
(
    select NPC_Traders.Nickname as Trader, Classes.Class as Items
    from NPC_Traders, Classes
    where Items IN (
               select npc.Tradeables
               from NPC_Traders npc 
               where npc.Tradeables LIKE '%1%' OR
                     npc.Tradeables LIKE '%2%' OR
                     npc.Tradeables LIKE '%3%' OR
                                    npc.Tradeables LIKE '%4%')
) AS Subquery

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.