I can also change table structure if needed. I can migrate to any other database just for this specific table. I am planning to move look for optimisation and faster alternatives. UPDATE: I am using MySQL at the moment with this setup: How to search multiple columns in MySQL Ask Question Asked 13 years, 3 months ago Modified 1 year, 9 months ago Viewed 155k times 49 I'm trying to make a search feature that will search multiple columns to find a keyword based match. The 20 can be in column number_one, 02 could be in column number_three and 12 in column number_four.Īlso, would it be better to use one column instead of five columns?Ĭolumn numbers contains 02-12-20-57-84 where - is the separator.Ī user ticks checkbox 02, 12 and 20. 1 Does this answer your question Checking if a string is found in one of multiple columns in mySQL mickmackusa at 22:56 Add a comment 4 Answers Sorted by: 23 You can use CONCAT () function: select from customer WHERE concat (city,name) like 'adelaide' You can add as many columns to the concat function as you like. I need to retrieve all the rows with all three number but I a number can be in any of the number_* column. Once a user select n checkbox, I need to build a query that look for a row that contains all those values, but a number can be in any of the five columns.Ī user ticks checkbox 02, 12 and 20. Support my content with a Tip.Each number_* column can contain a number from 01 to 90. At no additional cost to you, should you make a purchase by clicking through one of them, I will receive a commission. Receive a copy of my ebook, “10 MySQL Tips For Everyone”, absolutely free when you subscribe to the OpenLampTech newsletter.ĭisclosure: Some of this blog post’s services and product links are affiliate links. The Newsletter for PHP and MySQL Developers mysql> DELETE FROM products WHERE name LIKE Pencil Query OK, 2 row affected (0.00 sec). At no additional cost to you, should you make a purchase by clicking through one of them, I will receive a commission. A table is made up of columns (or fields) and rows (records). Warning: This join will hit id 4 when tags. Find your next digital purchase today!ĭisclosure: Some of this blog post’s services and product links are affiliate links. Try this: SELECT tags.id, tag FROM tags, tastings WHERE tastings.tags LIKE CONCAT ('', tags.id, '') or better, use the new join syntax: SELECT tags.id, tag FROM tags JOIN tastings on tastings.tags LIKE CONCAT ('', tags.id, '') Note the sandwiching of tag.id in so you find the id anywhere in it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |