|
Posted by Captain Paralytic on 10/12/06 11:14
MattMika wrote:
> I'm hoping someone can point me in the right direction on how to get
> what I want with this query.
>
> SELECT c.customers_firstname, c.customers_lastname,
> c.customers_email_address, ab.entry_street_address,
> ab.entry_street_address_2, ab.entry_city, ab.entry_postcode,
> z.zone_name as state
> FROM customers c
> LEFT JOIN address_book ab ON c.customers_id = ab.customers_id
> LEFT JOIN customers_info ci ON c.customers_id = ci.customers_info_id
> LEFT JOIN zones z ON ab.entry_zone_id=z.zone_id
> WHERE c.customers_newsletter="1"
> AND ci.customers_info_stores_id="10";
>
> This query works except the fact that the address_book table might
> have more that one entry for each customer. All I want is the first
> entry since this will be the billing address added when the customer
> signed up with us. How do I tell the query to only retrieve the first
> address_book entry?
>
> TIA
Well, as long as your address_book table has an incremental id column
for its primary index then you could use a variation of the query that
Strawberry posted here:
http://groups.google.co.uk/group/alt.php.sql/browse_frm/thread/456528317c40d8d1/ed022077f46cdec9?lnk=gst&q=strawberry&rnum=3#ed022077f46cdec9
You would need to reverse the less than comparison to get the first
occurance instead of the last one.
[Back to original message]
|