0

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
3
  • hard to say why it does not return data without seeing the data. If possible post some data in sqlfiddle.com One thing could be possible that the data is not present in Join tables. Commented Oct 30, 2014 at 11:38
  • Since it's an inner join, there has to be matching rows in all the tables. If you want to return rows that don't have matches everywhere, you need to use LEFT JOIN. Commented Oct 30, 2014 at 11:39
  • You have used columns from multiple tables, and performed joins. But you didn't specify your table name for a single column. Please specify table names for columns. Better use aliases. Commented Oct 30, 2014 at 11:58

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.