I'm studying SQL now.
SELECT *
FROM dates
WHERE user_id = '1891128461'
AND date1 = 'shop*'
This query can't find the data, while the following did find it:
SELECT *
FROM dates
WHERE user_id = '1891128461'
AND date1 = 'shopmeal'
What is in my wildcard query is wrong?
I had followed this explanation:
* represents zero or more characters; bl* finds bl, black, blue, and blob
and % returns the same output (see output of variable values)
command -->['/s', 'shop%']
'date1, date2, date3' --> shop%
['date1,', 'date2,', 'date3']--> ['shop%']
items for shop% does not exist
While if full word, it find (see output of variable values)
/s shophardware
command -->['/s', 'shophardware']
'date1, date2, date3' --> shophardware
['date1,', 'date2,', 'date3']--> ['shophardware']
items in a hardware category
- wires 2mm sink fan tubes 100mm
CodePudding user response:
The way you say AND date1='shop*' in SQL is
AND date1 LIKE 'shop%'
% matches any string of zero or more characters, and _ matches just one character. To get this kind of matching, you must say LIKE rather than =.
SQL's wildcard scheme evolved separately from UNIX's glob and regular expression scheme.
