andyd34 Posted July 3, 2009 Share Posted July 3, 2009 I have a MySQL database set up lik e this id, INT, autoincrement, primary country, varchar region, varchar city, varchar p_codes varchar I want to select a unique town with a unique first part of post code but don't have the first idae how to do it, can anyone help please[/code] Link to comment https://forums.phpfreaks.com/topic/164654-php-mysql-and-unique-records/ Share on other sites More sharing options...
backie Posted July 3, 2009 Share Posted July 3, 2009 SELECT * FROM Table WHERE p_codes REGEXP '^ML1 '; Clearly change ML1 to whatever unique post code you have. Link to comment https://forums.phpfreaks.com/topic/164654-php-mysql-and-unique-records/#findComment-868316 Share on other sites More sharing options...
andyd34 Posted July 3, 2009 Author Share Posted July 3, 2009 Sorry I was a bit vague in my question. I want to return a list like this echo $place['country'] . ', '.$place['county'].', '. $place['city'].' ('.substr($place['p_code'], 0, -3).')'; which would return United Kindom, Greater London, Walford (E17) United Kingdom, Lancashire, Wigan (WN1) United Kingdom, Lancashire, Standish (WN4) United Kingdom, Merseyside Liverpool (L1) United Kingdom, Cheshire, Ellesmere Port {L63) and so on the are several recurrences of some city fields and I have to full post code for each street/road in the cities. Hope this explains things a little more but thanks for you reply Link to comment https://forums.phpfreaks.com/topic/164654-php-mysql-and-unique-records/#findComment-868325 Share on other sites More sharing options...
backie Posted July 3, 2009 Share Posted July 3, 2009 SELECT DISTINCT country,county,city FROM Table This will extract only on row for each count of Country Count and City SELECT DISTINCT country,county,city,p_code FROM Table May not be what you are wanting, will look and see if the full post code has been extracted before and return it if it hasn't Hope this is more helpful Link to comment https://forums.phpfreaks.com/topic/164654-php-mysql-and-unique-records/#findComment-868332 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.