我有想要更快的Mysql查询 [英] I Have Mysql Query I Would Like To Make Faster

查看:50
本文介绍了我有想要更快的Mysql查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $ result1  = mysql_query(  SELECT distinct city FROM postcodedb WHERE web ='ALR'ORDER BY city die(mysql_error()); 
while($ row1 = mysql_fetch_array($ result1)){
$ city = $ row1 [ ' city'];
$ result = mysql_query( SELECT * FROM postcodedb WHERE area ='$ city'AND ='$ city'LIMIT 1 die(mysql_error());
while($ row = mysql_fetch_array($ result)){
$ city = $ row [ ' city'];
}





因此在数据库记录中看起来像这样:



id city area

1 Bromley Bromley - 我需要此记录

2 Bromley other1

3 Bromley other1

4伊尔福德伊尔福德 - 然后这一个

5伊尔福德其他1



所以我想要得到的是不同城市的列表,但对我来说重要的是我得到行ID,其中城市和地区都是一样的?



这个查询的工作原理我希望它可以工作但是有点慢,我相信有更好的方法可以达到同样的效果吗?



我希望自己清楚解释一下!





非常感谢您!



Nita

解决方案

result1 = mysql_query( SELECT distinct city FROM postcodedb WHERE web ='ALR'ORDER乙Y city die(mysql_error());
while(


row1 = mysql_fetch_array(


result1)){

$result1 = mysql_query("SELECT distinct city FROM postcodedb WHERE web='ALR' ORDER BY city") or die(mysql_error());
while($row1=mysql_fetch_array($result1)) {
$city = $row1['city'];
$result = mysql_query("SELECT * FROM postcodedb WHERE area='$city' AND city='$city' LIMIT 1") or die(mysql_error());
while($row=mysql_fetch_array($result)) {
$city = $row['city'];
}



So in database records look like this:

id city area
1 Bromley Bromley - i need this record
2 Bromley other1
3 Bromley other1
4 Ilford Ilford - and then this one
5 Ilford other1

So what I’m trying to get is listing of distinct cities, but important is for me is that i get row ID where both city and area are the same??

This query works as i want it to work but is a bit slow, and I believe there is a better way to achieve the same result??

I hope I explain myself clear !


Thank you very much in advance!

Nita

解决方案

result1 = mysql_query("SELECT distinct city FROM postcodedb WHERE web='ALR' ORDER BY city") or die(mysql_error()); while(


row1=mysql_fetch_array(


result1)) {


这篇关于我有想要更快的Mysql查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆