I have 40k records in my Database. i have written 2 SQL queries to achieve some result ! Unfortunately its taking to much time to run and server giving timeout error !
i am new to SQL so can any one help to merging my queries so that it will take less time to execute !
here is my code
$sql="SELECT Website, COUNT(*) FROM entry GROUP BY Website HAVING COUNT(*) = 2 ";
$run = mysql_query($sql);
while($row=mysql_fetch_array($run))
{
$Website = $row['Website'];
$sql2 = "SELECT * FROM entry where Website= '$Website' GROUP BY Address ";
$run2 = mysql_query($sql2);
while($row=mysql_fetch_array($run2))
{
$id = $row['id'];
$Website = $row['Website'];
$Name = $row['Name'];
$Address = $row['Address'];
$Country = $row['Country'];
$City = $row['City'];
}
}
Suggest me !