Monday 3 September 2018

MySQL Select Statement does not work

I am trying to create a select statement to be used in a view. The goal is to create a view showing office description, party description, candidate name and incumbant indicator. I have the following table is my database:

SELECT `OFFICE DESCRIPTION`,
       `PARTY DESCRIPTION`,
       `CANDIDATE NAME`,
       `INCUMBANT INDICATOR`
FROM   OFFICE,PARTY,CANDIDATE
WHERE  CANDIDATE.`OFFICE CODE`= OFFICE.`OFFICE CODE`
       AND CANDIDATE.`CANDIDATE ID`=`PARTY CANDIDATE`.`CANDIDATE ID`
       AND `PARTY CANDIDATE`.`PARTY CODE`=PARTY.`PARTY CODE`;

Error:
#1054 - Unknown column 'PARTY CANDIDATE.CANDIDATE ID' in 'where clause'

I have verified all the columns do exist for this SQL statement to work but for some reason it keeps returning an error that PARTY CANDIDAT.CANDIDATE ID doesn't exist. Any help would be appreciated. Let me know if there is anything more you need me to uplaod including table definitions and layouts.

  1. You need to enclose your field names with backticks
  2. You are missing Party Candidate from your FROM list
    SELECT `OFFICE DESCRIPTION`,`PARTY DESCRIPTION`,`CANDIDATE NAME`,`INCUMBANT INDICATOR`
    FROM OFFICE,PARTY,CANDIDATE,`PARTY CANDIDATE`
    WHERE CANDIDATE.`OFFICE CODE`=OFFICE.`OFFICE CODE`
        AND CANDIDATE.`CANDIDATE ID`=`PARTY CANDIDATE`.`CANDIDATE ID`
        AND `PARTY CANDIDATE`.`PARTY CODE`=PARTY.`PARTY CODE`;

0 comments:

Post a Comment