CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2010
    Posts
    161

    Run multiple statements to get result

    Hi there

    I need to run a query that select some specific results from a table and in addition a number of additional selected results from the same table.

    For example, I want to retrieve 20 results from a table of which 5 are already specified and the other 15 can be anything from the table.

    I have used the following query but it doesn't work

    Code:
    Select(
    select id,text from table 
    where id in ('1',
    '2',
    '3',
    '4',
    '5')
    ) as s_id,
    (
    select id,text 
    from table limit 15
    ) as m_tweets
    Can someone tell me if there's a way to achive this and how.

    Thank you

  2. #2
    Join Date
    Jan 2010
    Posts
    161

    Re: Run multiple statements to get result

    Ok found the solution
    For anyone who wants to run multiple statemtn union all,union will do the job
    The syntax is as follow:

    Code:
    SELECT * FROM table limit 10;
    union
    SELECT * FROM table limit 20;
    Note: If you don't want to get duplicates use union instead of union all.

  3. #3
    Join Date
    Sep 2006
    Posts
    635

    Re: Run multiple statements to get result

    I think it could be.....



    select id,text from table where id in ('1','2','3','4','5')
    union
    select id,text from table limit 15


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured