MasterACE14 Posted November 14, 2008 Share Posted November 14, 2008 bascially, I have 2 tables, and I want to select the columns from both using the 1 query. But I am getting a error. UserDetails is 1 table, Ranks is the other rank is a column in Ranks as is the userID column. ID is a column in UserDetails here's my query: <?php $query = mysql_query("SELECT * FROM `UserDetails`,`Ranks` ORDER BY `rank`.`Ranks` WHERE `UserDetails`.`ID`=`Ranks`.`userID` ASC") or die(mysql_error()." -can not select players!"); and I am getting... You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `UserDetails`.`ID`=`Ranks`.`userID` ASC' at line 1 -can not select players! any help is greatly appreciated. Regards, ACE Quote Link to comment https://forums.phpfreaks.com/topic/132674-solved-select-using-2-separate-tables-in-1-select/ Share on other sites More sharing options...
zenag Posted November 14, 2008 Share Posted November 14, 2008 ORDER BY Ranks.rank Quote Link to comment https://forums.phpfreaks.com/topic/132674-solved-select-using-2-separate-tables-in-1-select/#findComment-690008 Share on other sites More sharing options...
zenag Posted November 14, 2008 Share Posted November 14, 2008 SELECT * FROM `UserDetails`,`Ranks`WHERE `UserDetails`.`ID`=`Ranks`.`userID` ORDER BY Ranks.rank ASC Quote Link to comment https://forums.phpfreaks.com/topic/132674-solved-select-using-2-separate-tables-in-1-select/#findComment-690009 Share on other sites More sharing options...
MasterACE14 Posted November 14, 2008 Author Share Posted November 14, 2008 still no luck, the error is gone, but its not grabbing the data correctly. I think I may have to use a JOIN or something? Quote Link to comment https://forums.phpfreaks.com/topic/132674-solved-select-using-2-separate-tables-in-1-select/#findComment-690013 Share on other sites More sharing options...
MasterACE14 Posted November 14, 2008 Author Share Posted November 14, 2008 will UNION work with what I'm trying to do? EDIT: apparently not... The used SELECT statements have a different number of columns -can not select players! EDIT: Perhaps INNER JOIN is what I need? EDIT: I got it working now. <?php $query = mysql_query("SELECT * FROM `UserDetails` INNER JOIN `Ranks` ON `UserDetails`.`ID`=`Ranks`.`userID` ORDER BY `Ranks`.`rank` ASC") or die(mysql_error()." -can not select players!"); Thanks for your help zenag Quote Link to comment https://forums.phpfreaks.com/topic/132674-solved-select-using-2-separate-tables-in-1-select/#findComment-690017 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.