Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 191669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:21:40+00:00 2026-05-11T16:21:40+00:00

I have a comparison I’d like to make more efficient in SQL. The input

  • 0

I have a comparison I’d like to make more efficient in SQL.

The input field (fldInputField) is a comma separated list of “1,3,4,5”

The database has a field (fldRoleList) which contains “1,2,3,4,5,6,7,8”

So, for the first occurrence of fldInputField within fldRoleList, tell us which value it was.

Is there a way to achieve the following in MySQL or a Stored Procedure?

pseudo-code

SELECT *
FROM aTable t1
WHERE fldInputField in t1.fldRoleList

/pseudo-code

I’m guessing there might be some functions that are best suited for this type of comparison? I couldn’t find anything in the search, if someone could direct me I’ll delete the question… Thanks!

UPDATE: This isn’t the ideal (or good) way to do things. It’s inherited code and we are simply trying to put in a quick fix while we look at building in the logic to deal with this via normalized rows.. Luckily this isn’t heavily used code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:21:40+00:00Added an answer on May 11, 2026 at 4:21 pm

    I agree with @Ken White’s answer that comma-delimited lists have no place in a normalized database design.

    The solution would be simpler and perform better if you stored the fldRoleList as multiple rows in a dependent table:

    SELECT t1.*, r1.fldRole 
    FROM aTable t1 JOIN aTableRoles r1 USING (aTable_id) 
    WHERE FIND_IN_SET(r1.fldRole, fldInputField);
    

    (see the MySQL function FIND_IN_SET())

    But that outputs multiple rows if multiple roles match the comma-separated input string. If you need to restrict the result to one row per aTable entry, with the first matching role:

    SELECT t1.*, MIN(r1.fldRole) AS First_fldRole 
    FROM aTable t1 JOIN aTableRoles r1 USING (aTable_id) 
    WHERE FIND_IN_SET(r1.fldRole, fldInputField);
    GROUP BY t1.aTable_id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use list- or sexp- based operations: (defun remove-tex-cmd () (interactive)… May 11, 2026 at 11:32 pm
  • Editorial Team
    Editorial Team added an answer easier way is to multiply the contents with 1 and… May 11, 2026 at 11:32 pm
  • Editorial Team
    Editorial Team added an answer When you perform file management using wildcards from the command… May 11, 2026 at 11:32 pm

Related Questions

I have a comparison I'd like to make more efficient in SQL. The input
I have a mixed UI (Win App, WPF App, and soon an ASP.NET MVC
I have a class that acts as an item in a tree: class CItem(
I am currently faced with a difficult sorting problem. I have a collection of
I'm building a web application using Stripes and Spring. It needs to have a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.