Page 1 of 1
INNER JOIN - Two Tables, to unique fields. Won't work.
Posted: Thu Mar 28, 2013 10:35 am
by simonmlewis
Code: Select all
$result = mysql_query ("SELECT catid, id, sceneid, scene FROM products INNER JOIN products ON products.id = products_scenes.prodid WHERE catid = '$c'") or die (mysql_error());
I'm being told:
[text]Not unique table/alias: 'products'[/text]
What am I doing wrong here?
I thought you select all the fields you want, then say from what Table, and then on what fields in each table you want to join them.
Even though I have done this the way the tutorial described, "sceneid" and "scene" are not in products, but it wasn't in the table in the tutorial either, only in the 'joining' table.
Re: INNER JOIN - Two Tables, to unique fields. Won't work.
Posted: Thu Mar 28, 2013 11:30 am
by simonmlewis
I've worked it out, as I knew I had done this before.
Code: Select all
$result = mysql_query ("SELECT products.catid, products.id, scene FROM products INNER JOIN products_scenes ON products.id = products_scenes.prodid WHERE catid = '$c' GROUP BY scene") or die (mysql_error());
Re: INNER JOIN - Two Tables, to unique fields. Won't work.
Posted: Thu Mar 28, 2013 3:37 pm
by pickle
If your problem's solved, please edit your post subject to include [solved].
Re: INNER JOIN - Two Tables, to unique fields. Won't work.
Posted: Thu May 16, 2013 5:19 am
by simonmlewis
Actually, leading on from this, I have a similar INNER JOIN query that isn't working.
Code: Select all
$result = mysql_query ("SELECT subscribed_upload.email FROM subscribed_upload INNER JOIN unsubscribed ON subscribed_upload.email = unsubscribed.email WHERE email LIKE '%@%'") or die (mysql_error());
I have two tables. One is a fresh upload. The other is a list of emails that must NOT be included in an extract.
I need to extract all those from subscribed_upload WHERE email is NOT = unsubscribed.email.
I'm guess this has to be done in a JOIN... does it??
Re: INNER JOIN - Two Tables, to unique fields. Won't work.
Posted: Thu May 16, 2013 8:44 am
by VladSun
LEFT JOIN .... WHERE email IS NULL
Re: INNER JOIN - Two Tables, to unique fields. Won't work.
Posted: Thu May 16, 2013 10:06 am
by simonmlewis
Code: Select all
$result = mysql_query ("SELECT subscribed_upload.email FROM subscribed_upload LEFT JOIN unsubscribed ON subscribed_upload.email = unsubscribed.email WHERE email IS NULL") or die (mysql_error());
Column 'email' in where clause is ambiguous
Re: INNER JOIN - Two Tables, to unique fields. Won't work.
Posted: Thu May 16, 2013 10:08 am
by simonmlewis
Code: Select all
$result = mysql_query ("SELECT subscribed_upload.email FROM subscribed_upload LEFT JOIN unsubscribed ON subscribed_upload.email = unsubscribed.email WHERE unsubscribed.email IS NULL") or die (mysql_error());
?? Should this be it?