0

I have two columns round and day.

Round has a format like this: ,25,26,27,28,29,30,31,32,

Day has a format like this: ,1,2,3,4,5,6,7,

I am trying to do a query for a variable that is in a specific round, day and area.

The query looks like this:

SELECT * FROM variable WHERE round LIKE '%,' + '25' + ',%' AND day LIKE '%,' + '1' + ',%' AND area = 4 ORDER BY position ASC;

Although, I am getting nothing back. I have ready many pages on how to do this, but I haven't found a solution.

Is there something wrong with how I am writing it?

Thank you in advance.

3
  • 4
    Don't store lists of numbers in strings. SQL has this really great data structure for lists. It is called a table. Commented Oct 2, 2018 at 15:44
  • Perhaps use the || to concatenate instead of +. Although I really don't see a need to do concatenation at all as @mdem7 shows in their answer.
    – JNevill
    Commented Oct 2, 2018 at 15:48
  • The string concatenation operator is ||, not +. Commented Oct 2, 2018 at 15:48

1 Answer 1

2

Did you try this?

SELECT * FROM variable WHERE round LIKE '%,25,%' AND day LIKE '%,1,%' AND area = 4 ORDER BY position ASC;
1
  • Glad it worked, feel free to mark it as correct answer :) Commented Oct 2, 2018 at 15:52

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