Results 1 to 11 of 11

Thread: Query advice

  1. #1
    Join Date
    Aug 2008
    Posts
    464

    Unanswered: Query advice

    Hi

    I'm trying to write a query like:

    Select datetime, A, B, C, D from schema.table where B=1 and B=2 and B=3 and B=4 and datetime=trunc(sysdate)-1

    But I need the results to be sorted by B.

    Would appreciate any advice?

    Regards
    Sheraz

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >B=1 and B=2 and B=3 and B=4
    returns no rows
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool

    Have you tried adding the "ORDER BY" option to your query?
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  4. #4
    Join Date
    Aug 2008
    Posts
    464

    thanks

    thanks. I think I mis-explained by concern.

    I must select E and F when B=1 and G and H when B=2.

    Also, if possible in the same query, I'd like to select E and F when B=3 and G and H when B=4.

  5. #5
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    If/when B=1, then by definition B can NOT equal 2 at same time (B=1 and when B=2) so returns no rows once again.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  6. #6
    Join Date
    Aug 2008
    Posts
    464
    thanks I was just asking if it was possible to combine these conditions in one query something like nested queries, joins...etc I don't know.

  7. #7
    Join Date
    Dec 2003
    Posts
    1,074
    Through a UNION ALL?

    Code:
    select E as field1, F as field2
    from table
    where B=1
    union all
    select G as field1, H as field2
    from table
    where B=2
    --=cf

  8. #8
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Wink Sql tutorial for beginners?

    Quote Originally Posted by shajju
    thanks I was just asking if it was possible to combine these conditions in one query something like nested queries, joins...etc I don't know.
    Maybe you should spend some time reading an SQL tutorial.
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  9. #9
    Join Date
    Aug 2008
    Posts
    464

    Thank you

    Appreciate all the help guys. I too think a bit of reading is required on my part. It's just that I tend to fall asleep when doing so

  10. #10
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Select datetime, A, B, C, D from schema.table where B IN (1,2,3, 4) and datetime=trunc(sysdate)-1
    ORDER by B
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  11. #11
    Join Date
    Aug 2008
    Posts
    464
    Yep...that's what I did, thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •