searching for sku with or without dashes

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

searching for sku with or without dashes

Post by Luke »

I have a table (which I have no control over) which has some of its products skus listed with dashes (010-00433-00) and some without (0100043300). How would I

Code: Select all

SELECT id FROM products WHERE sku = 0100043300
and have it find 010-00433-00 or 0100043300

does it require regex? I hope not :(
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

If you like IN more than REGEXP

Code: Select all

SELECT
	id
FROM
	products
WHERE
	sku IN ('0100043300', '010-00433-00')
or

Code: Select all

SELECT
	id
FROM
	products
WHERE
	sku='0100043300'
	OR sku='010-00433-00'
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Write a separate script that updates the fields to not have dashes at all? :)
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

good call :D
Post Reply