logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
sql query question...

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related
View previous topic :: View next topic  
Author Message
Xildjian



Joined: 08 Jan 2005
Posts: 100

PostPosted: Sat Jan 26, 2008 17:03    Post subject: sql query question... Reply with quote

Wondering if someone could help with this type of query, can't seem to get the magic incantation.

This is for a serverstatus web page. I want to display:
PlayerName CharName Race SubRace Level

PlayerName lives in t1 and the others in t2. Each table has a PlayerID column. So I want to select the PlayerName based on this PlayerID which I want to select from t2 if IsOnline colum in t2 equals 1.

Make sense?

How can I setup a query so all the information I want to display is returned in a row for each character?

Any help would be appreciated.

Thanks!
_________________
Member Shadow of Iniquity development team
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Sat Jan 26, 2008 17:08    Post subject: Reply with quote

SELECT * FROM t2
INNER JOIN t1 ON t1.PlayerID=t2.PlayerID
WHERE t2.IsOnline=1

For further information read the MySQL Documentation:
http://dev.mysql.com/doc/
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Xildjian



Joined: 08 Jan 2005
Posts: 100

PostPosted: Sat Jan 26, 2008 19:37    Post subject: Reply with quote

virusman wrote:
SELECT * FROM t2
INNER JOIN t1 ON t1.PlayerID=t2.PlayerID
WHERE t2.IsOnline=1

For further information read the MySQL Documentation:
http://dev.mysql.com/doc/


Thanks that helps, but not exactly the result I need. I want to do something like this:

(SELECT PlayerName FROM table_player
INNER JOIN table_character ON table_player.PlayerID=table_character.PlayerID
WHERE table_character.IsOnline=1) UNION (SELECT CharName, Race, SubRace, OverallLevel FROM table_character WHERE IsOnline=1);

But since the columns are not the same the above doesn't work testing in the Query browser.
_________________
Member Shadow of Iniquity development team
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Sat Jan 26, 2008 19:48    Post subject: Reply with quote

Xildjian wrote:
Thanks that helps, but not exactly the result I need. I want to do something like this:



But since the columns are not the same the above doesn't work testing in the Query browser.
SELECT p.PlayerName, c.CharName, c.Race, c.SubRace, c.OverallLevel
FROM table_player AS p
INNER JOIN table_character AS c ON p.PlayerID=c.PlayerID
WHERE c.IsOnline=1
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Xildjian



Joined: 08 Jan 2005
Posts: 100

PostPosted: Sat Jan 26, 2008 20:38    Post subject: Reply with quote

virusman wrote:
Xildjian wrote:
Thanks that helps, but not exactly the result I need. I want to do something like this:



But since the columns are not the same the above doesn't work testing in the Query browser.
SELECT p.PlayerName, c.CharName, c.Race, c.SubRace, c.OverallLevel
FROM table_player AS p
INNER JOIN table_character AS c ON p.PlayerID=c.PlayerID
WHERE c.IsOnline=1


Sweet works like a charm!
Even learned a new command Smile

Thanks!
_________________
Member Shadow of Iniquity development team
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group