Re: SELECT until -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 08/02/10 12:55, Captain Paralytic wrote:
> On 8 Feb, 10:12, Johannes Keßler <m...@bananas-playground.net> wrote:
> On 08/02/10 11:08, nemaC wrote:
>
>
>
>>>>> Is there a way I need only select the rows until the customerid ?
>
>>>>> eg.
>>>>> SELECT * FROM table UNTIL customerId = 22
>>>>> ORDER BY price DESC
>
>>>>> with that I do not need to get all the data from the table.
>
>>>> SELECT <field you need> FROM table WHERE custumerId=22; ??
>
> No.
>
> I get the possition from counting the whole result table manually
>
> eg.
>
> $i=1;
> foreach($result as $entry) {
> $newArray[$entry['customerId']] = $i;
> $i++;
>
> }
>
> The possition is not stored in the database, and changes everytime you alter the
> "order by"
>
> regards,
> johannes keßler
> I really don't understand what you are after. As you point out, there
> is no such thing as a "position" of a row in a table.
> Maybe if you told us what you ultimately want to achieve by this?
Sorry if this is not as clear as it should be.
here is an example
customerid|name|price|points|sell
- ---------------------------------
1|name1|10|22|1
2|name2|3|1|25
3|name3|15|84|23
4|name4|122|81|22
SELECT * FROM table ORDER BY price DESC
result would be:
customerid|name|price|points|sell
- ---------------------------------
4|name4|122|81|22
3|name3|15|84|23
1|name1|10|22|1
2|name2|3|1|25
Now I want to know where in the list or at what possition a specific customer
is. If I sort by price, customer 3 is at place 2.
If I sort by points it would be at place 1.
But right now there is no such information at which possition the customer is, I
got this only by numbering the rows manually as described as my previous reply.
Now the problem is that everytime I want to get a possiton I need to query the
whole table with a different ORDER BY. And then number the rows manually.
If the table has 10000 rows you have to number 10000 rows. And you have the data
from 10000 rows.
Image if the customer is at possition 3 you could only number until you reach
this specific customer AND do not have to number all the 10000 rows, just to
find out that the customer is a row 3. numbering all the other 9997 rows is
useless and a wast of data which is pulled from the table.
So my question is if I can create a query which just does this without getting
all the data.
I hope it is more clear now. But english is not my primary language.
regards,
johannes keßler
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
iEYEARECAAYFAktv/78ACgkQE++2Zdc7EtdkAQCeNaAUcqqi5sTl+7fcH7MRObWa
xLYAniq/Tg6mzqbPeJmRgWb00wvqq5De
=4pBj
-----END PGP SIGNATURE----- |