Results 1 to 2 of 2

Thread: How to make the select statement in MS sql?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    208

    How to make the select statement in MS sql?

    I am developing windows application using C# and MS sql.
    I have the following tables.

    table1
    pkid Name
    101 Meles
    102 Zenawi
    103 Mekele
    104 Kenenisa

    table2
    pkid2 datepaid PKid
    10 13/3/2012 101
    11 16/4/2012 101
    12 25/9/2012 101

    13 14/9/2012 102
    14 27/9/2012 102
    15 15/10/2012 102

    now i want to select name from the first table table1 and the latest datepaid from the second table table2. both table is connected by foreign key(from table1 into table2.. PKid)
    i expect the resutlt to be
    Name datepaid
    Meles 25/9/2012
    Zenawi 15/10/2012
    how do i make the select statement please help me?
    thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: How to make the select statement in MS sql?

    This question has nothing specific to do with C#. SQL code is the same whether you're executing it in a management tool or in an application regardless of the language that application was built in. Please post your SQL questions in the Database Development forum in future.
    sql Code:
    1. SELECT t1.Name, MAX(t2.datepaid)
    2. FROM table1 t1 INNER JOIN table2 t2
    3. ON t1.pkid = t2.PKid
    4. GROUP BY t1.Name
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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