or maybe my inability to understand them .
I'm in a mess trying to get joins and unions right. I wished to combine Tables B&C, both having identical structures and tried the foll. 3 options all of which returned errors. The Unions work correctly when used without the Join and the Join works correctly for a single table but put them all in the same sql and errors flow even if the ORDER BY clause is removed.
So where am I going wrong ?
CODE 1
$sql11a = "SELECT * FROM `TableB`
UNION
SELECT * FROM `TableC`
INNER JOIN `TableA`
ON/ USING // (tried both options)
(`TableB`.Sid = `TableA`.Sid) || (`TableC`.Sid = `TableA`.Sid) ) // line 9
WHERE `TableA`.`Eid` = $group AND `TableA`.`Month` = $month AND `TableA`.`Year` = $year
ORDER BY `Binname` asc ";
$result11a = mysql_query($sql11a) or die (mysql_error());
if ($myrow11a = mysql_fetch_array($result11a))
{
do
{
ERROR:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.Sid = TableA.Sid) || (TableC.Sid = TableA.Sid) line 9
CODE 2
$sql11a = "SELECT * FROM `TableB`
UNION
SELECT * FROM `TableC`
INNER JOIN `TableA`
USING (Sid)
WHERE `TableA`.`Eid` = $group AND `TableA`.`Month` = $month AND `TableA`.`Year` = $year
ORDER BY `Binname` asc ";
$result11a = mysql_query($sql11a) or die (mysql_error());
if ($myrow11a = mysql_fetch_array($result11a))
{
do
{
ERROR :
The used SELECT statements have a different number of columns
CODE3
$sql11a = "SELECT * FROM `TableB`
UNION
SELECT * FROM `TableC`
INNER JOIN `TableA`
ON Sid
WHERE `TableA`.`Eid` = $group AND `TableA`.`Month` = $month AND `TableA`.`Year` = $year
ORDER BY `Binname` asc ";
$result11a = mysql_query($sql11a) or die (mysql_error());
if ($myrow11a = mysql_fetch_array($result11a))
{
do
{
ERROR:
Column 'Sid' in on clause is ambiguous