0

Here is a query with which I am checking whether a username is available or not in one table

 $query=mysql_query("SELECT * from tb_sponsar where username='$username'");

But,I am having two more tables named tb_company and tb_school and both tables have this field named username now I want to have a query that checks usernames from all the three tables...I am new to php so don't know how to do it.can anyone please help me in this regard?

I tried it like this

 $query=mysql_query("SELECT * from tb_sponsar where username='$username'" && "SELECT * from tb_company where username='$username'");

but after applying this query it is giving false result

Durai Amuthan.H
  • 30,333
  • 8
  • 151
  • 234

4 Answers4

0

Just try

  $query=mysql_query("SELECT * from tb_sponsar where 
username='$username'" AND "SELECT * from tb_company where username='$username'");
Arshid KV
  • 8,979
  • 3
  • 32
  • 35
0

Try this

$query=mysql_query("SELECT username from tb_sponsar where username='{$username}'"
. " UNION SELECT username from tb_company where username='{$username}'"
. " UNION SELECT username from tb_table3 where username='{$username}'");
Samar Haider
  • 872
  • 10
  • 21
  • when i am applying this query it is showing the same result for every username that is not available even if the username does not exist – user3572583 Jun 17 '14 at 08:10
0

Tray using UNION keyword to combine tables:

$query=mysql_query("SELECT username from tb_sponsar where username='$username' UNION SELECT username from tb_company where username='$username'");

You can also use JOIN but you need to have a relation between those tables.

Dusan
  • 761
  • 5
  • 16
0

try this bro

$query=mysql_query("SELECT * from tb_sponsar where username='$username' AND SELECT * from tb_company where username='$username' AND SELECT * from tb_school where username='$username'");
wrecklez
  • 335
  • 2
  • 4