Query Help
#3

A player's name should not appear more than once in the entire database. Seeing as a house can only be owned by one player you don't require an associative table here, but you do need to link it to the player table by means of the id. I don't think you need the "owner" field at all seeing as you already have a field "ownerid" which is probably linked like that.

So, if you want to load each house, along with the name of the player who owns it, you will need a join. If you want all houses regardless of whether they're currently owned use a left join. If you only want houses that are currently owned use an inner join.
PHP код:
SELECT houses.*, IFNULL(accounts.name'No-One') AS name FROM houses
LEFT JOIN accounts ON houses
.ownerid accounts.id 
Reply


Messages In This Thread
Query Help - by Dubya - 30.05.2015, 04:55
Re: Query Help - by BroZeus - 30.05.2015, 05:30
Re: Query Help - by Vince - 30.05.2015, 09:19
Re: Query Help - by Konstantinos - 30.05.2015, 09:23

Forum Jump:


Users browsing this thread: 2 Guest(s)