Cross table SELECT in MySQL
Posted: Fri Mar 03, 2006 8:09 am
Hi, I've been using MySQL for a while now but one habit I have is bugging me, as I think I can probably simplify the way I work. I think it involves cross-table joins but I've never quite 'got' this. For example, a value in one table relates to a value in another table. I have to get the value in the first table in order to retrieve the value in the second.
For example, you want to get the currency symbol for a particular country.
Is there a way of combining this into one SELECT statement? If so, what is it?
Thanks for your help.
For example, you want to get the currency symbol for a particular country.
Code: Select all
//get country
$sql = "SELECT country FROM customer_profiles WHERE (custid = '$custid')";
$result = mysql_query( $sql );
$row = mysql_fetch_assoc( $result );
extract($row, EXTR_OVERWRITE );
// get currency symbol
$sql = "SELECT currency_symbol FROM currencies WHERE (associated_country = '$country')";
$result = mysql_query( $sql );
$row = mysql_fetch_assoc( $result );
extract($row, EXTR_OVERWRITE );Thanks for your help.