Forum Moderators: coopster

Message Too Old, No Replies

I'll appreciate JOIN help

Tried to "fool around" but cannot get it ok

         

henry0

6:19 pm on Mar 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Join Problem:
I need to set a numrows query by joining two tables

I have a table named “aaa” with among all the cols:
name, state, city, phone, experience

Also a table named “rating”
with among a few cols: rate and phone

rate and phone are in both tables but none table has the same name of rows!
“rate” has no phone number dupe and no dupe rows
(but for a good reason dupe phone needs to exist in “aaa”

From table “aaa” I need to query name, state, city phone, experience
From table “rating” I need to query col “rate” where phone= phone from “aaa”

Then I will do a numrows to display (with pagination) all
Name, state, city, experience, phone and that rating from the other table

ericjust

6:44 pm on Mar 14, 2007 (gmt 0)

10+ Year Member



This seems like it would work assuming all of the phone numbers in "aaa" are contained in "rating". If there is a phone number that is not in the "rating" table it would not be included.

$start_limit = 0;
$end_limit = 10;

$query = "
SELECT a.name,a.state,a.city,a.experience,a.phone,r.rate
FROM aaa a,rating r
WHERE r.phone = a.phone
LIMIT {$start_limit},{$end_limit};
";

henry0

6:55 pm on Mar 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, yes it worked like a charm
I did not use LIMIT since I use my own pagination script
but at least for once think I understood what's under the hood :)

it saves me a lot of procedures for I was thinking that I would get away with a query and a sub-query!