Results 1 to 3 of 3

Thread: SQL Server 2005 Stored Procedure Query Help

  1. #1
    Join Date
    Jul 2008
    Posts
    4

    SQL Server 2005 Stored Procedure Query Help

    Hey,
    Obviously from the title, I need a little help with a query.

    I have 2 tables. One is a favorites that will look up into another.

    So in the favorites table I have 3 fields. UserName, ClientID, and timestamp. My stored procedure gets the username and gets the top15 entries in the table with the passed in username.

    This gives me the clientid (the favorites for that user if you will). Now I need to get all the other fields for that clientid passed into another select statement. How can this be done.

    So far I have:

    SELECT top 15*
    FROM Favorites
    WHERE username = @UserName
    order by Timestamp DESC

    Now I need to pass is clientID from that select and get back

    Select * from Clients
    Where Clients.ClientID IS IN (the first select's clientID)

    Thanks,

  2. #2
    Join Date
    Dec 2004
    Posts
    502
    SELECT * FROM Clients
    WHERE Clients.ClientID IN
    (SELECT top 15 ClientID
    FROM Favorites
    WHERE username = @UserName
    order by Timestamp DESC)

  3. #3
    Join Date
    Jul 2008
    Posts
    4
    Quote Originally Posted by nosepicker
    SELECT * FROM Clients
    WHERE Clients.ClientID IN
    (SELECT top 15 ClientID
    FROM Favorites
    WHERE username = @UserName
    order by Timestamp DESC)
    Sorry for the late response. But that was it 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
  •