mysql 加入其他表搜索

发布于 2024-12-17 19:43:28 字数 273 浏览 0 评论 0原文

SELECT * FROM
companies as C
LEFT JOIN usersSearchCache as UC ON C.id = UC.objectId
WHERE UC.userId = ? AND C.keywords LIKE ?

所以基本上我有一个表:usersSearchCache,它有一个 objectId,objectId 链接到公司表的 id,我需要搜索公司的关键字在用户的缓存中匹配的位置。

上面的查询不起作用,但我不明白为什么。

SELECT * FROM
companies as C
LEFT JOIN usersSearchCache as UC ON C.id = UC.objectId
WHERE UC.userId = ? AND C.keywords LIKE ?

So basically I have an table: usersSearchCache, that has an objectId, the objectId
is linked to the id of the companies table, I need to search where the keywords of the company are matching in the cache of the user.

The query above isn't working but I don't understand why.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你另情深 2024-12-24 19:43:28

我们在user表中得到了用户,所有这些用户都可以访问对象的页面,当他们访问这些页面时,会在表userSearchCache中创建一条新记录。

select * FROM userSearchCache UC
where UC.userId = ?

返回类似

userId,objectId
1,123
1,345

现在我得到的是一个搜索字段,用户在其中插入他们想要搜索的对象的名称,因此当前的查询是:

JOIN companies C ON UC.object_id=C.id

userId,objectId,keywords
1,123,"yoga,savate,pilates"
1,345,"tennis,biking,soccer"

要查找“biking”,我会使用 LIKE '%BIKING%'

select * 
FROM userSearchCache UC
JOIN companies C ON UC.object_id=C.id
where UC.userId = ? AND c.keywords LIKE '%'+?+'%'

你的关键字吗参数已包含通配符“%”

We got users in a user table, all those users can visit pages of objects, when they visit these pages, a new records is created in the table userSearchCache.

select * FROM userSearchCache UC
where UC.userId = ?

returns something like

userId,objectId
1,123
1,345

Now what I got is a search field, where the users inserts the name of the object they want to search, so the current query is:

JOIN companies C ON UC.object_id=C.id

userId,objectId,keywords
1,123,"yoga,savate,pilates"
1,345,"tennis,biking,soccer"

to find "biking", I would use LIKE '%BIKING%'

select * 
FROM userSearchCache UC
JOIN companies C ON UC.object_id=C.id
where UC.userId = ? AND c.keywords LIKE '%'+?+'%'

Does your keyword parameter already contain the wildcard characters '%'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文