PDA

View Full Version : need a query


yvorl
11-25-2008, 10:29 AM
Hi!

I've a table:

table0
id number version page date
1 5783001 00 01 20081015
2 5783001 00 02 20081015
3 5556661 05 01 20061015
4 5783001 01 01 20081111

and I'd like to write a query, which selects rows with a specific number with the same page numbers in a group and these ordered by date desc.

For example: SELECT from table0 WHERE number='5783001' ...????

I mean in the end a want them in a variable something like this:

$doc[0][0]='5783001-01-01-20081111'
$doc[0][1]='5783001-00-01-20081015'
$doc[1][0]='5738001-00-02-20081015'

I hope you understand my problem. :/

How can i do this?

Thx for the help

guelphdad
11-25-2008, 03:21 PM
add an order by clause. the variable stuff would be handled by your front end application.

yvorl
11-28-2008, 11:07 AM
I can make frontend app to do this of corse, I'm just wondering if there's a possibility to

1. select groups of rows by a condition
2. order these selected groups inside the group

with one query.

guelphdad
11-28-2008, 04:01 PM
You are misusing the term GROUP, in a database application a GROUP BY clause is used to collapse like groups for aggregate information.

for instance say you have cars and trucks and you want to total them you use a GROUP BY clause to get the totals

if you have the following data

auto_type, color, amount
car red 5
car blue 6
truck orange 3
car yellow 2
truck green 1


SELECT
auto_type,
count(*)
FROM yourtable
GROUP BY auto_type


gives you
car 13
truck 4

all you are asking about in your data above is to list them by
car
car
car
truck
truck

and all that is used to do that is an order by clause.

yvorl
12-01-2008, 09:14 AM
It's clear now, thank you for the explanation.