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

问题描述:

Guys I want to Select from table articles depending if code is in table called 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. Any help?

This is table inStock

enter image description here

And this is table articles

enter image description here

我想从表文章 code>中选择的人,具体取决于 code code >在名为 inStock code>的表中。 因此,例如,如果我在表 inStock code> 224中的列 code code>中,我需要选择具有该代码的Select * FROM articles code>,并且每个项目都相同。 有什么帮助吗? p>

这是表 inStock code> p>

p>

这是表文章 code> p>

p> DIV>

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

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

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: