-1
`SELECT leaderstbl.lfname AS leaders, IF(COUNT(vfname)>1,COUNT(vfname),0) AS followers, IF(COUNT(household)>1,COUNT(household),0) AS household FROM votersinfotbl WHERE vleaders IN (SELECT vleaders FROM votersinfotbl WHERE vaddress = 'ABACA') AND vleaders NOT IN ('NONE', 'none', 'None', '') AND vaddress = 'ABACA' AND household IN (SELECT vleaders FROM votersinfotbl WHERE vaddress = 'ABACA')

FULL OUTER JOIN leaderstbl ON votersinfotbl.lfname=leaderstbl.lfname
GROUP BY leaderstbl.lfname ORDER BY vleaders ASC` 

what seems to be the problem of my query sir?

it displays this error:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FULL OUTER JOIN leaderstbl ON votersinfotbl.lfname=leaderstbl.lfname GROUP BY l' at line 3

I am having trouble can someone help me?

PS: this is for my capstone thanks everyone for your help!

Incepter
  • 2,711
  • 15
  • 33

2 Answers2

1

mysql does not have full outer join, you can do left join two times or left and right join and union which actually work as like full outer join

select col1..coln from table1 t1 left join table2 t2 on t1.col=t2.col
union
select col1..coln from table2 t2 left join table1 t1 on t1.col=t2.col

or

select col1..coln from table1 t1 left join table2 t2 on t1.col=t2.col
union
select col1..coln from table1 t1 right join table2 t2 on t1.col=t2.col
Zaynul Abadin Tuhin
  • 31,407
  • 5
  • 33
  • 63
1

You are using WHERE clause before FULL OUTER JOIN. Try this:

SELECT leaderstbl.lfname                             AS leaders,
       IF(COUNT(vfname) > 1, COUNT(vfname), 0)       AS followers,
       IF(COUNT(household) > 1, COUNT(household), 0) AS household
FROM votersinfotbl
FULL OUTER JOIN leaderstbl ON votersinfotbl.lfname=leaderstbl.lfname
WHERE vleaders IN (SELECT vleaders FROM votersinfotbl WHERE vaddress = 'ABACA')
  AND vleaders NOT IN ('NONE', 'none', 'None', '')
  AND vaddress = 'ABACA'
  AND household IN (SELECT vleaders FROM votersinfotbl WHERE vaddress = 'ABACA')
GROUP BY leaderstbl.lfname
ORDER BY vleaders ASC