0

I have 2 tables, in the first tabel (Mail_Template) there are 3 columns:

  ID | Name   | Text
  1  | Mail1  | Text12345
  2  | Mail2  | Text654adsd
  3  | Mail3  | Text64das
  4  | Mail56 | T269a8sdfext

in the next table (DB_KD) i have the next columns:

 ID  | Client| Mail_Temp_ID
  1  | Alex  | 2,3
  2  | Ludi  | 1,2,3,4
  3  | Max   | 4
  4  | Elko  | 2

What i need is to search for the Client names and for all the coma separated ID´s (Mail_Temp_ID) output the Mail Templates. As an example, if I search for Alex Templates i should get:

ID | Name   | Text
2  | Mail2  | Text654adsd
3  | Mail3  | Text64das

Or if I searched for Max i schould get:

As an example, if I search for Alex Templates i should get:

ID | Name   | Text
4  | Mail56 | T269a8sdfext

Unfortunatley I was not able to do it so, i have tryd with the "IN" and the "FIND_IN_SET" functions, but unfortunatley nothing works for me. Can you give me some advice how to do it?

Strawberry
  • 33,750
  • 13
  • 40
  • 57
Acelando
  • 29
  • 10
  • Which version are you usingand take a look at https://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad – nbk Jun 22 '20 at 11:23
  • Are you able to restructure your tables? DB_KD seems not to be normalized... I would change the table and the data in a way that each Mail_Temp_ID becomes a unique row in conjunction with the client column... – Wolfgang Roth Jun 22 '20 at 11:24
  • Join using `FIND_IN_SET()` function. – Akina Jun 22 '20 at 11:32
  • Hi Wolfgang, hmm i could do that, or create another table just for this purpose. So there is not another way? – Acelando Jun 22 '20 at 11:36
  • @Akina, cann you show me how to do it? – Acelando Jun 22 '20 at 11:47

0 Answers0