user1993853
user1993853

Reputation: 31

QUERY sql database

PLEASE HELP FOR A QUERY

My Student_Master Table:-

ID Name  
1  AAA
2  BBB  
3  CCC
4  DDD

My Student Details Table

ID MastID Address
1   1     Address 1   
2   2     Address 2

Now I have a gridview which is bound to Student master table, now I want a custom column in my gridview called so that "The students who have address there status should be "Address Present" and for the student whose address is not present in table for them there status would be "Address NOT Present" Eg.

ID Name  Status
1  AAA   Address Present
2  BBB   Address Present 
3  CCC   Address NOT Present  
4  DDD  Address NOT Present

Upvotes: 0

Views: 64

Answers (1)

Hamlet Hakobyan
Hamlet Hakobyan

Reputation: 33391

Try this:

SELECT
    M.ID, 
    M.Name,
    CASE WHEN D.Id IS NULL
         THEN 'Address NOT Present'
         ELSE 'Address Present'
    END Status
FROM Master M
    LEFT JOIN Details D
        ON M.Id = D.MastID

Upvotes: 1

Related Questions