D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] SQL advice

 

Michael Mortimore wrote:
> you want to get 2 rows from 1 entry in the database, which i don't
> think you can easily do in SQL.
> 
> you could try something along the lines of:
> select distinct if(isnull(d1),d2,d1) as thedate, if(isnull(d1),n2,n1)
> as thename, if(isnull(d1),"paper due","") as thedescription, from
> (select seminardate as d1, name as n1 from seminars) as t1,
> (select paperduedate as d2, name as n2 from seminars) as t2
> 
> it's a pretty horrible solution though.

How about:

SELECT id, name, eventdate FROM
(
    SELECT id, name, date as eventdate
    FROM seminar
    UNION
    SELECT id, CONCAT(name, ' papers due'), papers_due AS eventdate
    FROM seminar
    WHERE NOT ISNULL(papers_due)
) AS foo
WHERE eventdate BETWEEN '2005-01-01 00:00' AND '2008-01-01 00:00';


I don't know if this is standard SQL or not but it works in MySQL.

Gem



-- 
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/linux_adm/list-faq.html