MySQL Forums
Forum List  »  Newbie

SubQuery Help
Posted by: Steven Weintraut
Date: August 15, 2004 02:33PM

Hi!

I'm having a blast with PHP and mySQL, but I've become stumped over a type of query that I haven't been able to figure out.

I have a customer table

I have another table which logs all of the dates when we visit each customer.

I put in a search screen to let someone search for a list of customers, say those that start with the letter "A", real easy.

In that same query however, I want to find all of those customers whose name starts with "A" and in the resulting list I want to display the number of days since the last visit.

I understand how to search for customers whose name starts with "A"

SELECT * from contacts where concat(FirstName,LastName) like "%a%"

I understand how to count the days until the last visit:

SELECT Min(To_Days(Current_Date()) - To_Days(calendarevents.EventDate)) FROM contacts,calendarevents WHERE calendarevents.CustomerLink=contacts.RecordID AND (To_Days(calendarevents.EventDate) <= (To_Days(CURRENT_DATE)))

how to I get the above calcuation query into the resultset for my "names starting with 'A'" query?

I thought I could do it with subqueries, but I haven't been able to figure it out yet.

Thanks in advance for any help!

Options: ReplyQuote


Subject
Written By
Posted
SubQuery Help
August 15, 2004 02:33PM
August 15, 2004 03:12PM
August 15, 2004 03:34PM
August 15, 2004 03:43PM
August 15, 2004 03:46PM
August 15, 2004 08:30PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.