Query-within-a-query with mySQL/PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is somewhat complicated, so I'll try to give examples with real- world data.

Basically, I'd like to know how I could take data like this, from mySQL:


2006
Liberty School
Central Coast, California, Central Coast, USA
Chardonnay

2006
Liberty School
Paso Robles, California, Central Coast, USA
Syrah

2006
Liberty School
California, California, USA
Cabernet Sauvignon

2005
Liberty School
Paso Robles, California, Central Coast, USA
Cabernet Sauvignon

2005
Liberty School
Central Coast, California, Central Coast, USA
Chardonnay

2005
Liberty School
California, California, USA
Cabernet Sauvignon

2005
Liberty School
California, California, USA
Zinfandel

2005
Liberty School
California, California, USA
Syrah

2005
Liberty School
Paso Robles, California, Central Coast, USA
Cabernet Sauvignon

2005
Liberty School
Paso Robles, California, Central Coast, USA
Syrah

2004
Liberty School
California, California, , USA
Cabernet Sauvignon

2004
Liberty School
Paso Robles, California, Central Coast, USA
Cabernet Sauvignon

etc....



and create a query which would return the data like this:


Liberty School Chardonnay (USA, California, Central Coast) 2007, 2006, 2005, 2004, 2003, 2002, 2001, 2000, 1997, 1985 Liberty School Cabernet Sauvignon (USA, California) 2006, 2005, 2004, 2003, 2002, 2001, 2000, 1999, 1998, 1997, 1996, 1995, 1990, 1982, 1976 Liberty School Cabernet Sauvignon (USA, California, Central Coast, Paso Robles) 2005, 1993 Liberty School Cabernet Sauvignon (USA, California, Sonoma County) 2003, 1984


Basically I somehow need to do a GROUP BY producer, and yet somehow at the same time, find out all the matching vintages (years), that go along with that group and return them the same time the producer group is returned.

Right now, my PHP/SQL query string is:

$query = 'SELECT * FROM wine WHERE MATCH(producer, varietal, appellation, designation, region, vineyard, subregion, country, vintage) AGAINST ( "' . $combostring . '" IN BOOLEAN MODE ) ORDER BY ' . $orderby . ', producer ASC LIMIT 0,100';

This produced the first list you see at the top of this email.

Any help is greatly appreciated.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux