Redan
/* */
- Joined
- Mar 6, 2014
- Messages
- 82
- Solutions
- 1
- Reaction score
- 13
I wonder if OtLand is a good place to ask for SQL support, but my request is related to my ots.
Ok, so here it is:
I've created 3 tables in my database
The query above works fine but now, I need to get auction winner name. So I simply add another JOIN like this:
In such case, the `winner_name` returns always NULL. What is the reason? Any idea how to make it work properly?
#Edit
I'm 100% sure every value is set correctly so the winner name should appear.
Ok, so here it is:
I've created 3 tables in my database
- players
- houses
- house_auctions
- id (values: 2 and 14)
- name (values: Kapman, Bongo)
- id (value: 58)
- owner_id (value: 14)
- id (value: 2)
- house_id (value: 58)
- winner_id (value: 2)
Code:
SELECT `houses`.`id`, `ow`.`name` AS `owner_name`
FROM `houses`
LEFT JOIN `house_auctions` AS `auctions` ON `auctions`.`house_id` = `houses`.`id`
LEFT JOIN `players` AS `ow` ON `ow`.`id` = `houses`.`owner_id`
WHERE `houses`.`id` = '58';
The query above works fine but now, I need to get auction winner name. So I simply add another JOIN like this:
Code:
SELECT `houses`.`id`, `ow`.`name` AS `owner_name`, `po`.`name` AS `winner_name`
FROM `houses`
LEFT JOIN `house_auctions` AS `auctions` ON `auctions`.`house_id` = `houses`.`id`
LEFT JOIN `players` AS `ow` ON `ow`.`id` = `houses`.`owner_id`
LEFT JOIN `players` AS `po` ON `po`.`id` = `auctions`.`winner_id`
WHERE `houses`.`id` = '58';
#Edit
I'm 100% sure every value is set correctly so the winner name should appear.