Hey,
This question is more suited I think to MySQL, but as I didn’t see a forum for that (I may just be blind and tired) I decided to post here, as I am calling this MySQL query from PHP.
Anyway, my question is this:
I am trying to get a drop-down box to populate from a MySQL db. The table is set up with an id primary key, but this is only because I can’t use multiple primary keys. I have two columns that I’m searching by: col_a and col_b, but I want to order by col_a.
Now, as primary keys go, there are instances when there are multiple rows that have the same value in col_a, but not col_a AND col_b.
I want to run a MySQL query that’s similar to this:
[code=php]
$query = “SELECT col_a, col_b FROM table ORDER BY col_a ASC”;
That works great, except, then I want to order by col_b (after it order’s by col_a)
Also, I want to somehow group by col_a and limit the number of rows that appear in a col_a group, but not the whole table. The query I envision looks something like this:
[code=php]
$query = “SELECT col_a, col_b FROM table GROUP BY col_a ORDER BY col_a ASC LIMIT 2”;
so that a drop down box would have something like this in it:
row 1: box 2000
row 2: box 1999
row 3: scissors 1999
row 4: tape 2004
but instead, with the above query, I get:
row 1: box 2000
row 2: scissors 1999
Any idea how I can accomplish this SQL statement? I probably haven’t been very clear and I can elaborate if the need arises.
Thanks for any help,
Jaelan