简体   繁体   English

根据另一个表中的存在,从表中选择

[英]Make Select from table depending of existence in another table

Guys I want to Select from table articles depending if code is in table called inStock . 我想从表格articles选择的人,具体取决于code是否在名为inStock表中。 So for example if I have in column code in table inStock 224 I need to Select * FROM articles having that code and for every item same. 因此,举例来说,如果我有在列codeinStock 224我需要SELECT * FROM articles具有代码和相同的每一个项目。 Any help? 有帮助吗?

This is table inStock 这是在inStock中的表格

在此输入图像描述

And this is table articles 这是表格articles

在此输入图像描述

Try with the following query: with inner join you can get this as code need to present in both table, hopefully you'll get your desired ans 尝试使用以下查询:使用内部联接,您可以获得此代码,因为代码需要在两个表中显示,希望您将获得所需的ans

select a.id,a.code,a.name,a.description,a.amount,a.color,b.price
from articles a inner join instock b
on a.code=b.code
SELECT articles.*, inStock.Price
FROM articles INNER JOIN inStock ON articles.code = inStock.code

INNER JOIN will return the records that are present in both the tables based on the columns that you are joining INNER JOIN将根据您要加入的列返回两个表中存在的记录

Please try the below query: 请尝试以下查询:

SELECT `A`.*, `S`.`price` 
FROM inStock S 
JOIN articles A 
ON (`S`.`code` = `A`.`code`);

Here you have a Demo for this: 在这里你有一个演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM