Jump to content

[SOLVED] SELECT using 2 separate tables in 1 select.


MasterACE14

Recommended Posts

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

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 :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.