php - sql1 to get names and sql2 to get Impressions, I need to sort names by Impressions -


hello have project , need me

$sql1 = "select count(*) num table1 column1='1'";      $total_results = mysql_fetch_array(mysql_query($sql1));      $total_results = $total_results[num];      while($row = mysql_fetch_array($sql1))          {  $sql2="select distinct column1 table2 column2='".$row['id']."' , left(date,10) between '".$datefrom."' , '".$dateto."'";  $res=mysql_query($sql2);  } 

sql1 names , sql2 impressions, need sort names impressions


name | impressions desc


a | 10

b | 8

c | 7


or


name | impressions asc


c | 7

b | 8

a | 10


thanks attention

i'll add same answer on previous question. can in join instead of separate queries;

select t1.id name, count(distinct t2.column1) impressions table1 t1 left join table2 t2   on t1.id=t2.column2 t1.column1 = 1   , left(date,10) between '2013-01-01' , '2013-12-31' group t1.id order impressions desc 

an sqlfiddle test with.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -