Results 1 to 5 of 5

Thread: Problem with query

  1. #1
    Join Date
    Feb 2004
    Posts
    4

    Unhappy Problem with query

    Hi

    I need to get info from two tables

    I need last course client attended for all clients result should show course id and date id and client id in any particular order.



    But only want one date and course for each user.

    table one

    Course ID

    table two

    Course Code
    Course Date
    Table two also has client ID

    This is the query that I have so far.

    SELECT MAX(DISTINCT dbo.tblCourse.dtmStartDate) AS [Last coursedate], dbo.tblCourse.strCourseCode, dbo.tblClientCourse.lngPrimaryId
    FROM dbo.tblCourse INNER JOIN
    dbo.tblClientCourse ON dbo.tblCourse.cntCourseId = dbo.tblClientCourse.lngCourseId
    GROUP BY dbo.tblCourse.strCourseCode, dbo.tblClientCourse.lngPrimaryId

    i am using MS SQL server 2000

    Thanks Tried so many things

    AB
    Last edited by AB1234; 02-18-2004 at 12:53 PM.

  2. #2
    Join Date
    Mar 2003
    Posts
    468
    you should have a client table and then try something like this:

    select clienttable.clientid, a.coursecode,a.coursedate
    from clienttable, tabletwo a
    where clienttable.clientid = a.clientid
    and a.coursedate = (select max(b.coursedate) from tabletwo b where b.clientid = a.clientid)

    if you don't have a client table, get one, you have a de-normalized model.

    if you can't get one, re-post with full table definitions and we will try and help.

  3. #3
    Join Date
    Feb 2004
    Posts
    4
    will this work with ms sql server?

    thanks

    AB

  4. #4
    Join Date
    Mar 2003
    Posts
    468
    pretty much standard sql.
    you could always give it a try

  5. #5
    Join Date
    Feb 2004
    Posts
    4
    Hi

    the above Query does not work in MS SQL SERVER 2000

    any other Ideas?

    AB

Posting Permissions

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