0

I'm using PHP and under localhost using Wamp. I have 2 tables from my database which has a huge data almost 13,000 plus each table. I want to check if NameFromA from TableA exist in NameFromB from TableB. I have this code working when I try to use small amount of data around 100 data.

SELECT * FROM TableA WHERE EXISTS (SELECT * FROM TableB WHERE  NameFromA = NameFromB)

My problem is when I try running it and comparing the 13,000 plus data nothing happens. It has no output.

mar
  • 53
  • 5

2 Answers2

1

Try this:

SELECT 
  TableA.* 
FROM 
  TableA 
  INNER JOIN TableB ON (TableA.NameFromA = TableB.NameFromB)

If it is still slow, may be you have problem in the DB or the timeout time is too short.

You can also try to run this in MySql management too to see how long that query will take.

One more thing. The data that you retreive must be send to web server. If your table contains a lot of data for each row and there are a lot of rows this also will take time.

EDIT:

Ok @mar. You have to make a little troubleshooting to find where is the problem.

First: if your PC is powerfull enought. Because for normal PC and Server 13k records are nothing.

Second: are you sure that there are at least one name from table A which is presented in table B?

Third: try to run query in external SQL tool - not in php. If it retunrs correct set quickly, then the problem is in php.

Bogdan Bogdanov
  • 1,707
  • 2
  • 20
  • 31
1

Create index on column NameFromA in TableA and NameFromB in TableB.

Try below query:

SELECT a.* 
FROM TableA AS a, TableB AS b
WHERE a.NameFromA = b.NameFromB
Samir Selia
  • 7,007
  • 2
  • 11
  • 30