Tech Off Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

sql subquery help

Back to Forum: Tech Off
  • User profile image
    harumscarum

    Since I do not work with 400 data any more my sql skills are diminishing! I have 3 subqueries that return different types of orders

    select * from
    (select * from foo where order='great') as tbGreatOrders,
    (select * from foo where order='good') as tbGoodOrders,
    (select * from foo where order='avg') as tbAvgOrders


    Each of the queries above return data individually but I want to merge them into one result set. The above sql will return 0 rows. help?

    edit:
    resolved.....UNION is my friend!

  • User profile image
    Maddus Mattus

    Because you are trying to merge result sets into fields!

    Edit: Oh no wait, maybe you should try this:

    SELECT * FROM Order WHERE Field = 'value'

    UNION ALL

    SELECT * FROM Order WHERE Field = 'something else'

    UNION ALL

    SELECT * FROM Order WHERE Field = 'None of the above'

  • User profile image
    Matthew van Eerde

    select * from foo where order in ('great', 'good', 'avg')

  • User profile image
    Maddus Mattus

    Matthew van Eerde wrote:
    select * from foo where order in ('great', 'good', 'avg')


    Better still!

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.