[英]SQL Select Where Join Table
對您的數據庫設計做一些假設:
name
列在attributes
表中,attr_id, name
組合是唯一的,並且attribute_vals
表中有一個val
列。聽起來您想要一個簡單的連接,通過屬性表中的名稱來限制值表。
然后,您可以在單個查詢中獲取關聯的attribute_vals
數據。
SELECT
`av`.`id`,
`av`.`attribute_id`,
`av`.`value`
FROM `attributes` AS `a`
INNER JOIN `attribute_vals` AS `av`
ON `a`.`id`=`av`.`attr_id`
WHERE `a`.`name`= 'weight'
此查詢為您獲取屬性“重量”的所有屬性值。 這是你想要的嗎?
select *
from attribute_vals
where attribute_id in (select id from attributes where name= 'weight');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.