user4198152
user4198152

Reputation:

My MySQL query will not return any results?

My MySQL query keeps returning with no results even though I think it should, I've probably made a silly mistake. So a fix would be fantastic. Thanks

SELECT SQL_CALC_FOUND_ROWS business_title, CONCAT(School_title, ', ', County, ', ', Town, ', ', Street_title, ', ', Postcode)
FROM `me-datab`.`business_main_location`
    INNER JOIN `business_site`
        ON `business_site`.Find_Me= `business_main_location`.Find_Me
    INNER JOIN `Personal`
        ON `Personal`.Personal_ID = `business_main_location`.Personal_ID
    INNER JOIN `address`
        ON `address`.Address_ID = `business_main_location`.Find_Me

Upvotes: 0

Views: 53

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269603

In all likelihood, one of your joins has no matching values. You can use left join instead of inner join to return results:

SELECT SQL_CALC_FOUND_ROWS business_title, CONCAT(School_title, ', ', County, ', ', Town, ', ', Street_title, ', ', Postcode)
FROM `me-datab`.`business_main_location`
    LEFT JOIN `business_site`
        ON `business_site`.Find_Me= `business_main_location`.Find_Me
    LEFT JOIN `Personal`
        ON `Personal`.Personal_ID = `business_main_location`.Personal_ID
    LEFT JOIN `address`
        ON `address`.Address_ID = `business_main_location`.Find_Me;

One possibility is the join on Address; it looks suspicious.

However, if you really want help, try setting up a SQL Fiddle (www.sqlfiddle.com) with sample data and your query.

Upvotes: 2

Related Questions