获取相关项目并将其作为链接输出

发布于 2024-12-11 21:21:27 字数 792 浏览 0 评论 0原文

table1products 具有字段:

products_id
products_price
products_status = 1( In Stock )
products_url

table2products_description 具有字段:

products_id(equals products_id in table products )
products_name

我想获取五个相关产品名称(有库存)及其价格,与产品名称的某些部分相匹配。 例如,产品名称为 $product_name。我想获得五个相关产品名称(有库存)及其价格。

$query = "select products_id , products_price, products_name
          from products p
          left join products_description pd on  p.products_id=pd.products_id and products_status = 1 and ....";`

像这样的匹配:如果产品名称是True Blood Season 1 DVD,我想显示五个以“True Blood Season”开头的项目。产品名称可能是其他名称。不仅仅是《真爱如血》季节

我如何用 SQL 编写这个?

table1 : products has the fields:

products_id
products_price
products_status = 1( In Stock )
products_url

table2 : products_description has the fields:

products_id(equals products_id in table products )
products_name

I want to get five relative products name(in stock) and its price, which matches by some part of the products name.
For example, the product name is $product_name. I want to get five relative products name(in stock) and its price.

$query = "select products_id , products_price, products_name
          from products p
          left join products_description pd on  p.products_id=pd.products_id and products_status = 1 and ....";`

The match like this: if a product name is True Blood Season 1 DVD I want to show five items which begin with "True Blood Season ". the products name maybe others. it not only True Blood Season

How do I write this in SQL?

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

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

发布评论

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

评论(1

醉梦枕江山 2024-12-18 21:21:27
SELECT `products_id`, `products_price`, `products_name` FROM `products` p
LEFT JOIN `products_description` pd ON p.products_id = pd.products_id 
WHERE `products_name` LIKE 'True Blood Season%' AND `products_status` = 1 
ORDER BY `products_name` LIMIT 5;

应该是像上面这样的,但这只是我的想法。

SELECT `products_id`, `products_price`, `products_name` FROM `products` p
LEFT JOIN `products_description` pd ON p.products_id = pd.products_id 
WHERE `products_name` LIKE 'True Blood Season%' AND `products_status` = 1 
ORDER BY `products_name` LIMIT 5;

Should be something like the above, but that is just off the top of my head.

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