I have a visitor table that looks like this:
VID Name Address DOB
001 Bob 101 St 03/05/2001
002 James 505 Rd 02/06/1985
003 Jill 201 Place 04/06/1970
And a visits table that looks like this:
VID Date Reason
001 05/07/2012 Family
001 06/01/2012 Family
003 03/02/2011 Other
I want to do a join query between these two on VID (which I already did) but also have the query show all (multiple) results from visits. So the results would look like:
Name DOB Visits
Bob 03/05/2001 05/07/2012 Family, 06/01/2012 Family
James 02/06/1985
Jill 04/06/1970 03/02/2011 Other
Is this possible? I attempted a subquery like:
SELECT Name, DOB, (SELECT Date, Reason FROM visits AS H WHERE H.VID=visitor.VID) As Visits FROM visitor;
But that gave me the obvious Subquery returned more than 1 value error. The data would be parsed by PHP, but I was hoping to accomplish this in one query.
You can use a
FOR XML PATHconstruct to concatenate your results into one columnNote that various date formats are supported with convert. I have used
101in the example wich translates tomm/dd/yyyy.Have a look at MSDN for all styles supported by convert.