Jump to content

SQL: query help plz


dug

Recommended Posts

Hi all,

Can someone care to please help me answer the questions below for this query?

SELECT c.ID AS 'Course ID',
date_format(c.start_date,'%d/%m/%Y') AS 'Start Date',
date_format(c.end_date,'%d/%m/%Y') AS 'End Date' ,
t.description AS 'Course Description',

FROM media_courses AS c
INNER JOIN media_courses_type AS t
ON t.ID = c.media_courses_type_ID

WHERE c.start_date > NOW()
GROUP BY c.ID
ORDER BY c.start_date ASC

what does the query above would return?

how do i Re-write the query to retrieve all courses in the past that a name that starts with Cert

how do i Re-write the query to return all courses that are more than 1 day in length



Cheers

Dug
Link to comment
https://forums.phpfreaks.com/topic/19012-sql-query-help-plz/
Share on other sites

Currently, it's returning all future courses... though I don't see the need for a GROUP BY, since it's an INNER JOIN, and will only return one record per media_course record anyway.  You should be able to change the where clause easily to check the "past" and examine the course title; for duration, simply subtract the start & end dates.
Link to comment
https://forums.phpfreaks.com/topic/19012-sql-query-help-plz/#findComment-82231
Share on other sites

[quote author=fenway link=topic=106082.msg424019#msg424019 date=1156862276]
Currently, it's returning all future courses... though I don't see the need for a GROUP BY, since it's an INNER JOIN, and will only return one record per media_course record anyway.  You should be able to change the where clause easily to check the "past" and examine the course title; for duration, simply subtract the start & end dates.
[/quote]

Hi fanway,

thanks for the help.  as for the second question is this what you had in mind:
SELECT c.ID AS 'Course ID',
date_format(c.start_date,'%d/%m/%Y') AS 'Start Date',
date_format(c.end_date,'%d/%m/%Y') AS 'End Date' ,
t.description AS 'Course Description',

FROM media_courses AS c
INNER JOIN media_courses_type AS t
ON t.ID = c.media_courses_type_ID

WHERE c.end_date < NOW()
AND t.description LIKE 'Cert'
ORDER BY c.start_date ASC

and as for substracting the the dates how do i do that?  Can you plz care for a reply?

thanks

dug
Link to comment
https://forums.phpfreaks.com/topic/19012-sql-query-help-plz/#findComment-82243
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.