0

用户表:

userID | name
1      | John
2      | Mary
3      | Jack

项目表(用户将选择并存储到 mysql

itemID | name   | item 
1      | Mary   | pants, jeans
1      | John   | jacket, shirt
1      | Jack   | jacket, shirt

描述表(根据用户选择的项目检索描述)

descID | item          | descOne | descTwo
1      | jacket, shirt | Nice!   | Great   
1      | pants, jeans  | good    | Nice    
1      | dress, jeans  | Nice!   | Great   

如果我想检索 Mary 的值,我的 select sql 语句应该是什么?

目前我有这个->

SELECT 
    d.item, 
    d.descOne, 
    d.descTwo, 
    i.name , d.item
FROM description d 
INNER JOIN items i 
WHERE d.item = i.item ON;
4

1 回答 1

2
SELECT 
    u.name,
    d.descOne, 
    d.descTwo, 
    d.item
FROM users as u
LEFT JOIN items as i ON i.name = u.name
LEFT JOIN description as d ON d.item = i.item
WHERE u.name = 'Mary'
于 2013-01-09T18:21:31.510 回答