Query-within-a-query with mySQL/PHP

From: Date: Sat, 25 Oct 2008 16:13:46 +0000
Subject: Query-within-a-query with mySQL/PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-282426@lists.php.net to get a copy of this message
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.

« previous php.general (#282426) next »