Mysql和php - 比较它们并从两个值中恢复一个

时间:2012-01-31 17:22:38

标签: mysql sql

Category      Make    
BUS           hiace
Car           honda
bus           hiace

预期结果:
巴士(hiace) - 在下拉列表中 汽车(本田) - 在不同的下拉列表中

 <SCRIPT TYPE="TEXT/JAVASCRIPT">
 function setup(ans) {
 lit = ''
 if (ans == 'bus') {
  <?php 
 $result = mysql_query("select Category from auto
group by Make"); ?>

lit = lit+ '<select name="q4" ONCHANGE="alert(document.quest.q4.value)" style="width:130px; background-color:#FFCC33; font-weight:bold; font-size:12px;" >'
lit = lit+ '<option>MAKE</option>'
 <?php while($row = mysql_fetch_array($result))
 {
$make = $row['Make'];
//print $make;
?>
var make = "<?php echo $make; ?>"
lit = lit+ '<option>'+make+'</option>'

  <?php }?>
lit = lit+ '</select>'
}
 </script>

5 个答案:

答案 0 :(得分:0)

SELECT * 
FROM table 
where ID IN (select MIN(ID) 
                FROM table 
                GROUP BY Name)

答案 1 :(得分:0)

SELECT * 
FROM table 
GROUP BY Name

答案 2 :(得分:0)

对于匹配的随机ID,请尝试

SELECT * FROM table_name GROUP BY Name;

或者如果您想要具有相同名称的最大ID

SELECT MAX(ID),Name FROM table_name GROUP BY name;

如果你想要第一个ID,这自然也适用于MIN()。

答案 3 :(得分:0)

SELECT id,name FROM tbl_names GROUP BY name ORDER BY id ASC?

答案 4 :(得分:0)

select min(ID), Name
from tablename
group by Name