Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Show top 10

  1. #1
    New Coder
    Join Date
    Apr 2005
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Show top 10

    Hi,

    I would like to show the top 10 tuples from my querys, doesn't seems to work. I am using ms sqlserver
    Please help.

    Code:
    SELECT TOP 10 * FROM
    (
    	SELECT Fbuser_id_friend FROM BEFRIEND WHERE Fbuser_id --Select the friends of the user friends
    	IN(SELECT Fbuser_id_friend FROM BEFRIEND WHERE Fbuser_id = '1000') 
    	AND Fbuser_id_friend <> '1000'
    	EXCEPT
    	SELECT Fbuser_id_friend FROM BEFRIEND
    	WHERE Fbuser_id = '1000' 
    )

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Quote Originally Posted by ooiyh
    I am using ms sqlserver
    and posted in MySQL forum?
    Request a moderator to move your thread to "other databases" section
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,554
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    Ummm...you are doing SELECT *, but the only field you can possibly get from that * is the one and only field SELECTed by the inner query.

    Maybe if you explained:
    (1) Your table layout; what fields are where and what they mean
    and
    (2) What you want as your final result.

    It's hard to figure out what you are after when all we can see is some code that obviously isn't working.

  • #4
    New Coder
    Join Date
    Apr 2005
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I got my final result, which is the code in (). But I just want to show only 10 out of my final result. How do I do it?

    Cheers

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,554
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    As I said, I wish you had EXPLAINED the problem instead of showing code that might work but might not be best.

    But since you insist:
    Code:
    SELECT TOP 10 B.* FROM
          (
    	SELECT Fbuser_id_friend FROM BEFRIEND WHERE Fbuser_id --Select the friends of the user friends
    	IN(SELECT Fbuser_id_friend FROM BEFRIEND WHERE Fbuser_id = '1000') 
    	AND Fbuser_id_friend <> '1000'
    	EXCEPT
    	SELECT Fbuser_id_friend FROM BEFRIEND
    	WHERE Fbuser_id = '1000' 
        ) AS S, BEFRIEND AS B
    WHERE B.Fbuser_id_friend = S.Fbuser_id_friend
    ORDER BY ???what???
    Selecting a TOP 10 is meaningless if you don't give SQL something to order by and thus find the top 10 whatevers.


  •  

    Posting Permissions

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