0

I have arrary like below

this1,this2,this3

sometime

this1,this2,this3,this4

etc,

I want find result from my table where tags like array1 or array2 or array3 or sometime like where tags like array1 or array2 or array3 or array4

I have wall_tags have rows like below

this1,this2
this1
this1,this2,this3
etc

I have my current query is like below

SELECT * FROM tbl_wallpaper WHERE `wall_tags` like '%search_value%' ORDER BY id ASC LIMIT 3

I am not able to make it working with arrary, Let me know if someone can help me for do it.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Nisha Jain
  • 25
  • 5

1 Answers1

1

As far as i can see your query works and i added another Query that does the same

Schema (MySQL v8.0)

CREATE TABLE tbl_wallpaper (
  `id` INTEGER,
  `wall_tags` VARCHAR(23)
);

INSERT INTO tbl_wallpaper
  (`id`, `wall_tags`)
VALUES
  ('1', 'this1,this2,this3'),
  ('2', 'sometime'),
  ('3', 'this1,this2,this3,this4');

Query #1

SELECT 
    *
FROM
    tbl_wallpaper
WHERE
    `wall_tags` LIKE '%this2%'
ORDER BY id ASC
LIMIT 3;

| id  | wall_tags               |
| --- | ----------------------- |
| 1   | this1,this2,this3       |
| 3   | this1,this2,this3,this4 |

Query #2

SELECT 
    *
FROM
    tbl_wallpaper
WHERE
    FIND_IN_SET('this1',`wall_tags`) > 0
ORDER BY id ASC
LIMIT 3;

| id  | wall_tags               |
| --- | ----------------------- |
| 1   | this1,this2,this3       |
| 3   | this1,this2,this3,this4 |

View on DB Fiddle

nbk
  • 45,398
  • 8
  • 30
  • 47
  • Hello sir! Thanks for nice answer. I think You do not understood my question. I want get result where wall_tags LIKE this1 or this2 or this3. Thanks! – Nisha Jain Apr 06 '20 at 11:53
  • I have search value is in array . sometime its this1,this2 or sometime its this1,this2,this3 etc. Thanks! – Nisha Jain Apr 06 '20 at 11:55
  • What does wall_tags look like also such comma seperated string? You should try to bukd your where clause, where you explode your searchstrig and build from that your where clause. – nbk Apr 06 '20 at 12:05
  • Thanks! I have added sample row data which I have in my table called wall_tags – Nisha Jain Apr 06 '20 at 12:08
  • yeah i thought so, you must do it like this https://stackoverflow.com/a/11543329/5193536, mysql isn't good with comma separated columns, thtat's why we don't use them. see https://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad – nbk Apr 06 '20 at 12:11