mysql - Sql Un-Wizardry: Compare values from one list in another -


I have a comparison that I want to make more efficient in SQL.

There is a comma separated list of input fields (FldInputField) "1,3,4,5"

The database has a field (fldRoleList) in which "1,2,3, 4,5,6,7,8 "

Therefore, for the first instance of fldInputField within fldInoleFist, tell us what it was worth.

Is there a way to get the following in MySQL or stored process?

/ pseudo-code

I can guess there are some tasks that are most suitable for this type of comparison? I can not find anything in search, if someone can guide me, then I will remove the question ... thank you!

Update: This is not the ideal (or good) way to do something. This code has been inherited and we are trying to recover only a quick, while we look for it to be handled through normalized lines. Fortunately this heavy code is not used.

I agree with Ken White that the comma-delimited list in generalized database design There is no place

The solution will be easy and perform better if you store fldRoleList as multiple rows in a dependent table:

  SELECT t1 *, Connect to R1.fldRole aTable t1 aTableRoles r1 USING (aTable_id) where FIND_IN_SET (r1.fldRole, fldInputField);  

(see MySQL function)

But it outputs multiple rows if multiple roles match a different input string than a comma. First Matching Role:

  SELECT t1. *, With MIN, if you want to restrict the result to a row per  aTable  entry, then MIN (R1.fldRole) before ASTABLE T1, a tablerong R1 user (first_find) Where FIND_IN_SET (R1FFRRol, FFIDInputField) is included; Group T1 ATBUL_ID;  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -