[英]LIKE function on MySQL not picking up similar words
I am currently using db-fiddle.com to practice my SQL code.我目前正在使用 db-fiddle.com 来练习我的 SQL 代码。
I have two tables.我有两张桌子。
'Customers': '顾客':
Customers_id![]() |
PracticeName![]() |
Location![]() |
PracticeType![]() |
Subref![]() |
---|---|---|---|---|
1 ![]() |
Hermitage Vets![]() |
Essex![]() |
Farm![]() |
P030022 ![]() |
2 ![]() |
West End Vets![]() |
Edinburgh![]() |
Companion![]() |
P030023 ![]() |
'Samples': “样品”:
Samples_id ![]() |
Subref![]() |
SampleType![]() |
det![]() |
FAM ![]() |
VIC![]() |
Gel_result![]() |
---|---|---|---|---|---|---|
1 ![]() |
P030022_1 ![]() |
SWAB![]() |
MHYPCR![]() |
38.72 ![]() |
35.00 ![]() |
null ![]() |
2 ![]() |
P030022_2 ![]() |
SWAB![]() |
MHYPCR![]() |
34.23 ![]() |
30.05 ![]() |
null ![]() |
3 ![]() |
P030022_3 ![]() |
SWAB![]() |
MHYPCR![]() |
34.00 ![]() |
29.99 ![]() |
null ![]() |
4 ![]() |
P030022_4 ![]() |
SWAB![]() |
MHYPCR![]() |
30.00 ![]() |
37.10 ![]() |
null ![]() |
(There are more subref samples and more columns in Samples but I didn't want to clutter the page.) (Samples 中有更多 subref 示例和更多列,但我不想弄乱页面。)
There can be multiple samples as part of one subref that is why I made them two tables with the underscore to define results per sample.可以有多个样本作为一个子引用的一部分,这就是为什么我用下划线将它们制作成两个表来定义每个样本的结果。
I want to be able to see all the samples that are part of the Subref next to PracticeName.我希望能够看到属于 PracticeName 旁边的 Subref 的所有示例。 So the end result is the Samples table but with the PracticeName column attached.
所以最终结果是 Samples 表,但附加了 PracticeName 列。
Sorry if this is not the best way to format things but I am a very new beginner.抱歉,如果这不是格式化事物的最佳方式,但我是一个非常新的初学者。
I tried both these codes, which apparently executed but nothing showed up in the results:我尝试了这两个代码,这些代码显然已执行,但结果中没有显示任何内容:
SELECT * FROM Customers, Samples WHERE Customers.Subref LIKE (Samples.Subref + '%');
SELECT * FROM Customers, Samples WHERE Customers.Subref LIKE concat (Samples.Subref, '%');
I have also tried creating another table to do many-to-many queries but again it executed with no results:我还尝试创建另一个表来执行多对多查询,但它再次执行但没有结果:
Customers_id INT UNSIGNED NOT NULL
, Samples_id SMALLINT UNSIGNED NOT NULL
, PRIMARY KEY pk_Customers2Samples (Customers_id, Samples_id)
);
WHERE Customers.Subref like 'Samples.Subref%';
I am not sure what I am doing wrong.我不确定我做错了什么。
Any advice appreciated, please be nice.任何建议表示赞赏,请善待。
Looking to yourdata sample.. due the repsence of _n at the end yous houdl use the inverse (match for string from customers + % like the string in samples)查看您的数据示例..由于最后 _n 的表示,您应该使用逆向(匹配来自客户的字符串 + % 像示例中的字符串)
SELECT *
FROM Customers
INNER JOIN Samples ON Samples.Subref LIKE concat (Customers.Subref, '%')
the string for Sample in your data containg more chats respect the value in customers then can't macth.. the opposite should work您的数据中 Sample 的字符串包含更多聊天尊重客户的价值然后无法计算.. 相反应该有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.