If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Select from multiple tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-18-11, 13:26
Jedna Jedna is offline
Registered User
 
Join Date: Apr 2011
Posts: 2
Select from multiple tables

Hi, I have some troubles with select from multiple tables. There are 3 tables - books (id, name), borrow_log(id_book, id_user), users(id, name). All i want to do is select books that havent been borrowed by specific user (e.g. "John"). I wonder if it could be done w/o subqueries?
Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 04-18-11, 13:32
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
look at the various permutations of the join construct
MySQL :: MySQL 5.0 Reference Manual :: 12.2.8.1 JOIN Syntax
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 04-18-11, 14:33
Jedna Jedna is offline
Registered User
 
Join Date: Apr 2011
Posts: 2
I went through it many times, but i cant get it to work. I have this query:

select * from book as b
left join borrow_log as bl on b.id = bl.id_book
left join users as u on u.id_users = cl.id_user
where u.nick <> "John"

but i dont know what to do so as it do not return books that John's already borrowed - there are still rows with the same book id but different user

Last edited by Jedna; 04-18-11 at 15:15.
Reply With Quote
  #4 (permalink)  
Old 04-21-11, 00:00
GreyWolf GreyWolf is offline
Registered User
 
Join Date: Apr 2011
Posts: 2
Not sure if its gonna work but you can try this.

SELECT users.name, books.name
FROM users,books.borrow_log
WHERE books.id=borrow_log.id=users.id
Reply With Quote
Reply

Tags
multiple, select, tables

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On