在我的数据库中,我有两个相关的表: ims_products 和 ims_order_details 。他们有以下结构:
ims_order_details
- OD_ID(PK)
- P_ID(FK)
- od_price
- od_quantity
ims_products
- P_ID(PK)
- p_name
- p_category
我想 从ims_products中选择p_category 其 p_id 在 中相同ims_order_details
答案 0 :(得分:2)
select p. p_category
from ims_products p
inner join ims_order_details o
on p.p_id = o.p_id
答案 1 :(得分:2)
$this->db->select('p_category');
$this->db->join('ims_order_details ','ims_order_details.p_id = ims_products.p_id,'inner');
$query = $this->db->get('ims_products');
if ($query && $query->num_rows()>0)
return $query->result();
答案 2 :(得分:1)
SELECT A.p_category
FROM ims_products A
LEFT JOIN ims_order_details B
ON A.p_id = B.p_id
WHERE B.od_price IS NOT NULL