Re: How do I order by some of the rows in a column. Not all.
Date: 13 Oct 2001 06:31:06 -0700
Message-ID: <9q9fmq0bom_at_drn.newsguy.com>
In article <47c6b9be.0110130115.3f228624_at_posting.google.com>,
jacob_nordgren_at_hotmail.com says...
>
>It seems as if you don't understand my question. There is no column
>named "Title" since my database model is very general.
>
>The only column that exists is the PRODUCT_PROPERTY
>
>If I use ORDER BY PRODUCT_PROPERTY the result will be ordered by all
>properties. I want to order by the rows that has
>PRODUCT_PROPERTY.PROPERTYID = 1 ("Title").
>
Its probably that your question doesn't make sense to us.
You have a result set that is:
>> > SELECT DISTINCT P.ID AS ID
there is no product_property.propertyid to order by and even if there were, what
does "I want to order by the rows that have that column = 1" mean???
It does not compute. By the time you do the distinct, all of the other columns are gone, vanished, squashed out of the result set. You cannot order by something you do not have and your request to order by rows that have that value = 1 doesn't make sense in a SQL sense.
>/ Jacob
>
>"Jim Kennedy" <kennedy-family_at_home.com> wrote in message
>news:<W8Dx7.23785$JN.84448_at_news1.sttls1.wa.home.com>...
>> put order by title at the end.
>> Jim
>> "Jacob Nordgren" <jacob_nordgren_at_hotmail.com> wrote in message
>> news:47c6b9be.0110120622.57febc70_at_posting.google.com...
>> > Hi,
>> >
>> > I have the following tables
>> >
>> > PRODUCT_GROUP
>> > ID (INT)* 'Example 1
>> > NAME (VARCHAR) 'Example "Books"
>> >
>> > PRODUCT
>> > ID (INT)* 'Example: 1
>> > PRODUCTGROUPID (INT) 'Example: 1
>> >
>> > PROPERTY
>> > ID (INT)* 'Example 1
>> > NAME (VARCHAR) 'Example "Title"
>> >
>> > PRODUCT_PROPERTY
>> > PRODUCTID (INT)* 'Example 1
>> > PROPERTYID (INT)* 'Example 1
>> > VALUE (VARCHAR)* 'Example "Learn SQL in 24 hours"
>> >
>> > If I want to find books with titles like "SQL" I use the following query:
>> >
>> > SELECT DISTINCT P.ID AS ID
>> > FROM PRODUCT P, PRODUCT_PROPERTY PP
>> > WHERE P.ID = PP.PRODUCTID
>> > AND P.PRODUCTGROUPID = 1
>> > AND PP.PROPERTYID = 1 AND UPPER(PP.VALUE) LIKE '%SQL%'
>> >
>> > My question is: How can I sort the result by the property "title".
>> >
>> > Thanks for your help,
>> >
>> > Jacob
-- Thomas Kyte (tkyte_at_us.oracle.com) http://asktom.oracle.com/ Expert one on one Oracle, programming techniques and solutions for Oracle. http://www.amazon.com/exec/obidos/ASIN/1861004826/ Opinions are mine and do not necessarily reflect those of Oracle CorpReceived on Sat Oct 13 2001 - 15:31:06 CEST