-1

I have table named 'categories' and it has one column name 'catvalues' with values see example below:

catvalues
------------------------
Party wear,Plain,Classic

Party wear,Plain

Party wear,Classic

now i want like query which when i search for 'Party wear,Classic' it should return 2 rows like below:

catvalues
---------------------------
Party wear,Plain,Classic

Party wear,Classic
Kara
  • 6,115
  • 16
  • 50
  • 57
  • You want the same row returned twice but you want to alter the value on the second return???? – Zane Apr 10 '14 at 19:03
  • i have no idea what your asking. – DidIReallyWriteThat Apr 10 '14 at 19:04
  • Please clarify your specific problem by adding the code you've tried. As it's currently written, it’s hard to tell exactly what you're asking. – Kermit Apr 10 '14 at 19:04
  • 2
    How are you passing search string? Are they two separate words or one word? Which RDBMS are you using? – rs. Apr 10 '14 at 19:05
  • 1
    OP what you really ought to do is not store comma separated values this way. – Zane Apr 10 '14 at 19:15
  • possible duplicate of [Comma separated values in a database field](http://stackoverflow.com/questions/738133/comma-separated-values-in-a-database-field) – Lamak Apr 10 '14 at 19:21

1 Answers1

1

maybe something like...

 SELECT * FROM table
  WHERE catvalues LIKE '%Party wear%Classic%'

but i really need more info about your questions

This sounds like your trying to put to much information into one column.

DidIReallyWriteThat
  • 1,033
  • 1
  • 10
  • 39
  • Aside from obvious syntax errors, this would not work. – Kermit Apr 10 '14 at 19:07
  • im curious to know why? – DidIReallyWriteThat Apr 10 '14 at 19:08
  • If the value in the row is `Classic,Party wear`. The *correct* solution is to normalize. – Kermit Apr 10 '14 at 19:14
  • 1
    The values stated are clearly Party wear,Plain,Classic Party wear,Plain Party wear,Classic The person did not ask for a lesson in table management. The question was how can I find this in my table. Explain how my solution, given the data set, does not do that. If the value in the row is Classic, Party wear, you are correct, however it is not. – DidIReallyWriteThat Apr 10 '14 at 19:16
  • 1
    Because OP explicitly says that they are searching for `Party wear,Classic`. What is the mechanism that will convert that to `'%Party wear%Classic%'`? – Kermit Apr 10 '14 at 19:18
  • But the result set asks for Party wear,Plain,Classic Party wear,Classic Show me the correct answer. – DidIReallyWriteThat Apr 10 '14 at 19:20
  • There isn't enough information to formulate a proper answer. – Kermit Apr 10 '14 at 19:20
  • What more information do you need? You have a dataset and the desired result. Just because it is a poorly formulated question does not make my answer incorrect. The CORRECT answer is the one I provided. The answer you give, change your table, solves no immediate problem. – DidIReallyWriteThat Apr 10 '14 at 19:21
  • Actually, the immediate problem is that the design is poor which leads to poor solutions. – Kermit Apr 10 '14 at 19:25
  • @Kermit I have no idea what your goal is. Every answer provided here is to change your dataset. Long term is this a good table design? No. But if the op wants to do it this way, I'm not in the habit of telling a person my way is the only way. You should change your dataset, but if you don't this gives you the desired results. To say this will not means you have no idea how SQL works. – DidIReallyWriteThat Apr 10 '14 at 19:27
  • 1
    Your answer does give an idea of how to go about solving the problem in case of a bad design. It doesn't follow, however, that the person doesn't need to be told their design is bad when it clearly *is* bad. It is not about your way or my way but about good/bad practices. So, no, the OP didn't ask for a lesson, but they might still need one. And please don't forget that this is a public resource and many people may come across this thread in search of solutions to similar problems. – Andriy M Apr 10 '14 at 20:00