Column not found on the left

    "SELECT `articles`.`name`, `articles`.`description`,`articles`.`startPrice`,`articles`.`creationDate`," 
                        + "`bids`.`date`, `bids`.`price`,`bids`.`userId`"
                        + " FROM `articles` LEFT JOIN `bids` ON `articles`.`id` = `bids`.`articleId`"
                        + " WHERE 1"

      

java.sql.SQLException: Column 'articles`.`id` was not found.

bids

the table has no records, but just wanted to try this as my understanding is that Left Join shows all the records in the table on the left, even though there are no records in the right table.

I changed Left Join by Inner Join and the query runs without error with a result of null records (as expected).

MySql version is 5.7.18

table of articles:

enter image description here

Some tests:

An example of a request that works Ok without errors:

"select `articles`.`id`, `articles`.`name`, `articles`.`description`,`articles`.`startPrice`,`articles`.`creationDate`," + 
"`bids`.`date`, `bids`.`price`,`bids`.`userId`"
                                + " FROM `articles` INNER JOIN `bids` ON  `articles`.`id` = `bids`.`articleId` "
                                + " WHERE 1"

      

I am also trying to restart my MySql server and the same thing happens.

I am using java and JDBC with

statement.executeQuery()

      

+3


source to share


2 answers


I don't know why, but it was fixed using the Java Statement class instead of PreparedStatement to execute the query.



0


source


Try the following:



"SELECT `articles`.`name`, `articles`.`description`,`articles`.`startPrice`,`articles`.`creationDate`," 
                        + "`bids`.`date`, `bids`.`price`,`bids`.`userId`"
                        + " FROM `articles` LEFT JOIN `bids` ON  `bids`.`articleId` = `articles`.`id`"
                        + " WHERE 1"

      

0


source







All Articles