Click here to get back home

3 way join in mysql

 HomeNewsGroups | Search | About
 alt.www.webmaster    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
3 way join in mysql herc777 05-10-2005
Get Chitika Premium
Posted by herc777 on May 10, 2005, 8:39 pm
Please log in for more thread options


Here's the original query that lists accounts that aren't yet approved.


$pending = mysql_query("
select banneruser.id, banneruser.login
from banneruser left join bannerstats
on banneruser.id=bannerstats.uid
where approved='0'
order by login asc");


I want to join a 3rd table so it only lists accounts that have the
banner uploaded. I can do it in normal SQL with a cartesian join but I
don't know the syntax of the left join. Bannerurls will be missing
some UIDs that are in banneruser.



$pending = mysql_query("
select banneruser.id, banneruser.login, bannerurls.bannerurl
from banneruser left join bannerstats left join bannerurls
on banneruser.id=bannerstats.uid and banneruser.id=bannersurls.uid
where approved='0'
order by login asc");


good 1st try?

Herc


Posted by Toby Inkster on May 11, 2005, 8:44 am
Please log in for more thread options



> I can do it in normal SQL with a cartesian join but I
> don't know the syntax of the left join. Bannerurls will be missing
> some UIDs that are in banneruser.

The SQL way to LEFT JOIN foo, bar and quux is:

SELECT a,b,c,d
FROM (foo LEFT JOIN bar ON foo.x=bar.y) AS baz LEFT JOIN quux ON
baz.w=quux.z
WHERE b=1
ORDER BY c
LIMIT 5;

Not sure if MySQL supports this. PostgreSQL does. If you're doing a clot
of complex queries, PostgreSQL is what you want.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Similar ThreadsPosted
Godaddy problem with ASP.NET 2.0 and MySQL using MySQL ODBC 3.51 Driver February 10, 2006, 2:00 am
Brand New ! Join Before Anybody ! February 21, 2006, 12:26 pm
new top list--join now March 3, 2006, 8:24 pm
Join "Thejetsets" November 17, 2005, 9:27 pm
She is inviting to all of you to JOIN ... November 23, 2005, 4:08 am
Look first, very interesting........ and than try join. November 15, 2006, 12:22 pm
join this group June 20, 2007, 3:54 am
JOIN THIS FOR FREE!!!!! July 29, 2007, 7:31 pm
join this Randomizer September 10, 2007, 8:34 am
Join this friendly webring October 13, 2005, 11:28 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap