Jump to content

Multiple tables


TEENFRONT

Recommended Posts

Hey Hey

I have a database with 3 tables. Tables are, users1, users2, and users3. to make things simple lets say they all have 1 column "username".

I wanna do this
$username = "Adam";
$sql ="SELECT username FROM user1, user2, user3 WHERE username = '$username'";


But the username, Adam, is only in 1 of the 3 tables. So the above doesnt work, it just fails to find Adam. Yet if i just do it with 1 table like this..

$username = "Adam";
$sql ="SELECT username FROM user1 WHERE username = '$username'";

it will find Adam if Adam is in users1.

I need to be able to locate Adam from all 3 tables. How do i do this?
Link to comment
Share on other sites

well i thought it was this.....

$username = "Adam";

$sql = "SELECT user1.username AS user1, user2.username AS user2, user3.username AS user3 FROM user1, user2, user3 WHERE user1.username = '$username' OR user2.username = '$username' OR user3.username = '$username';";
$results = mysql_query($sql) or die(mysql_error());

while($array = mysql_fetch_array($results))
{

echo $array['user1'];

echo"<br><br>";

echo $array['user2'];

echo"<br><br>";

echo $array['user3']; 
}

but it only works if Adam is in all 3 tables.... so maybe someone could help
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.