我有兩個表(書籍和借閱)。除了查詢以外遇到問題
我想從表Books
中選擇全部。 但首先它會檢查BookID
是否存在於表Borrowed
中,如果它存在且其Status
= 1,它將不會被包含在select *語句中。
我都試過,但它不工作
select * from Books
except
select `BookdID` where `Status`=1
請幫助我。這是我的表
書籍:
| BookID | Title | Author |
|:-----------|------------:|:------------:|
| 1 | The Stars | William Evan |
| 2 | Science 3 | Vhong Navaro |
| 3 | Let It Burn | Jun Ryl |
| 4 | Sky Below | Jason Midfle |
| 5 | Wish It | Shan Uddle |
借:
| BookID | BorrowerID | Status |
|:-----------|------------:|:------------:|
| 6 | 12 | 0 |
| 5 | 4 | 0 |
| 2 | 3 | 1 |
| 18 | 6 | 1 |
| 5 | 3 | 0 |
我的目標輸出:
| BookID | Title | Author |
|:-----------|------------:|:------------:|
| 1 | The Stars | William Evan |
| 3 | Let It Burn | Jun Ryl |
| 4 | Sky Below | Jason Midfle |
| 5 | Wish It | Shan Uddle |
*(BookID 2 is is not shown because in the table `Borrowed`, BookID 2's `Status` = 1)*
[在查詢中使用除外時出現錯誤]的可能重複(http://stackoverflow.com/questions/16092353/error-when-using-except-in-a-query) – Armfoot