Forum Moderators: coopster
i need to do a few queries,
my table looks something like this
+----+--+---+
¦info¦ 1 ¦ 1 ¦
+----+--+---+
¦more¦ 1 ¦ 2 ¦
+----+--+---+
¦some¦ 1 ¦ 3 ¦
+----+--+---+
¦wow¦ 2 ¦ 1 ¦
+----+--+---+
¦yes ¦ 2 ¦ 2 ¦
+----+--+---+
i have one column that groups the data, and one that creates the seperate "call numbers" for that group.
i need to find the biggest value in the first column, then find the highest value in that group
i would appreciate code, but more than that, i would like a place to learn the structure of the queries, PHP.net is very unhelpful for that.
thanks
SELECT * FROM table ORDER BY column2 DESC, column3 DESC;
You're right, you won't find much help on SQL on the PHP site. Better off trying the MySQL tutorial [dev.mysql.com] or search the net for "learn sql".
in the case i provided
$col2 = "2";
$col3 = "2";
even though column 3 has a 3 in it, that row has a lower value in column 2
$sql = "SELECT * FROM table ORDER BY column2 DESC, column3 DESC";
$rows = mysql_query($sql);
$row = mysql_fetch_assoc($rows);
$col2 = $row['column2'];
$col3 = $row['column3'];
print "$col2<br />";
print "$col2<br />";
one thing though,
how can i allow that if a user enters the address as page.php?col2=1
then it will find the biggest value for col3 with respect to that col2?
i took a stab in the dark by making it so that if a value is already present for col2 it will use this query instead
$sql = "SELECT * FROM table WHERE col2 IS $col2 ORDER BY col3 DESC";
it didn't work