ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  SQL Subqueries
Subject:   A little SQL Subquery help, please?
Date:   2004-12-14 22:02:03
From:   LFaler
This explanation is great, but I'm having a problem applying it to something.


I have a table that contains 4 columns. "ID", "Name", "Yes/No", "Date". There is only one record per day per name. What I would like is for it to return the information as follows:


___________________________________
| Name | Date 1 | Date 2 | Date 3 |
-------------------------------------
| Name 1 | Yes/No | Yes/No | Yes/No |
| Name 2 | Yes/No | Yes/No | Yes/No |
| Name 3 | Yes/No | Yes/No | Yes/No |


I've been toying with the following query, but it isn't returning it right. How should I write it?


"SELECT DISTINCT a.Name, (SELECT YesNo FROM L_Mail_Log b WHERE Date=1/2/2004 AND Name = a.Name) AS [1/2/2004], (SELECT YesNo FROM L_Mail_Log b WHERE Date=1/3/2004 AND Name = a.Name) AS [1/3/2004], (SELECT YesNo FROM L_Mail_Log b WHERE Date=1/4/2004 AND Name = a.Name) AS [1/4/2004] FROM L_Mail_Log a"


1 to 1 of 1
  1. A little SQL Subquery help, please?
    2004-12-21 12:34:42  msantoyo [View]

1 to 1 of 1