Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 dont know how to fix this query =(

Author  Topic 

metroix
Starting Member

16 Posts

Posted - 2008-07-30 : 10:34:13
the query is
$result = mysql_query("SELECT accounts.loggedin, guilds.logobg as uno, guilds.logobgcolor as dos, guilds.logo as tres, guilds.logocolor as cuatro, characters.name, characters.job, characters.level, guilds.name as gname, characters.hp, characters.mp, characters.exp, characters.fame, characters.str, characters.dex, characters.luk, characters.int, characters.ap FROM characters, guilds, accounts where characters.guildid = guilds.guildid and characters.accountid = accounts.id and characters.name = '$name' order by level DESC LIMIT 1", $db);

my problem is that some CHARACTERS dosent have guildid (default is 0) so the query will no show me nothing if the character dosent have a GUILDID because of this :
where characters.guildid = guilds.guildid


example:
sam has guild.guildid and a characters.guildid so if i use the query for sam ill get the info

example 2:
chris DO NOT have character.guildid(default = 0) i cant get the info for chris =/

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-30 : 10:38:44
USE LEFT JOIN


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

mbuono
Starting Member

6 Posts

Posted - 2008-07-30 : 10:52:22
khtan is right.
mysql should be enabled (depending on the version) to understand the ansi standard for the equijoin using the "JOIN" syntax.

since the COLUMN NAME is the same in each table, try:

SELECT ...
FROM characters
LEFT JOIN guids ON (guildid)

or

...
FROM characters NATURUAL JOIN guilds

(but only use that if there are no other like-named columns in each table... in fact, don't use NATURAL JOIN at all. haha).

_MBuono
Go to Top of Page

metroix
Starting Member

16 Posts

Posted - 2008-07-30 : 12:41:01
im using MYSQL 5.0
can u give me a lil more help i tried this
FROM characters, LEFT JOIN guilds ON (guildid)
but i got errors =/
Go to Top of Page

mbuono
Starting Member

6 Posts

Posted - 2008-07-30 : 13:13:14
you have an extra ","

FROM characters LEFT JOIN guilds ON (guildid)

or try

FROM characters
LEFT JOIN guids ON characters.guildid = guilds.guildid

_MBuono
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-30 : 20:59:50
quote:
Originally posted by metroix

im using MYSQL 5.0
can u give me a lil more help i tried this
FROM characters, LEFT JOIN guilds ON (guildid)
but i got errors =/


This is a Microsoft SQL Server forum. Please post question on MYSQL over at mysql.com


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -