Reputation: 79
I have been trying to create something of which I am not even sure if it's even possible, I have looked for similar things on Stackoverflow and Google, but with no results.
What am I trying to do?
I got two tables, one is called Book
and the other one is called UserBook
. The Book
table stores different information about a book and the UserBook
has a columns like UserId
and ISBN
and DateCreated
.
Book
Unique id = ISBN
UserBook
Unique id = ISBN, UserId
Currently I am trying to write a SQL query which returns all the books, and adds a temp column which is called IsVisible
(default value is set to True) but when the ISBN
number and UserId
are found in the UserBook
it will change the temp value of IsVisible
to false in the final result.
My current query so far is this:
SELECT
Book.ISBN, Book.Title, Book.ImagePath, Book.Summary, Book.AmountAvailable, 'True' AS IsVisible
FROM
Book;
Is what I am trying to do even possible?
Upvotes: 1
Views: 429
Reputation: 3834
I think you are trying to do something like this:
SELECT b.ISBN,
b.Title,
b.ImagePath,
b.Summary,
b.AmountAvailable,
CASE when ub.isbn is NOT NULL then 'False' else 'True' END AS IsVisible FROM Book b
LEFT OUTER JOIN USERBook ub on ub.isbn = b.isbn
Upvotes: 2