Tuesday 4 September 2018

Mysql command does not return rows

I have a SQL command which I know data exists with the criteria, but when I run the query it doesn't return rows:

SQL:
SELECT `USER_ID`, `CAR_ID`, `AD_ID`, `BRAND`, `MODEL`
, `YEAR`, `PRICE`, `MILEAGE`, `GEARBOX`, `STATUS`, `COLOR_IN`, `COLOR_OUT`
, `BODY`, `FUEL`, `ABOUT`, `MAIN_PHOTO`
FROM (`ads`, `cars`, `ad_extras`)
WHERE `ads`.`USER_ID` = '2'

What should I do?
EDIT:
When I do SELECT * it also doesn't return data.
when I select from 2 tables it retaurns data. So I can't select from 3 tables right?

It's likeky that one of your tables is empty. The result of that is empty.You should use a query like this one
SELECT `USER_ID`, `CAR_ID`, `AD_ID`, `BRAND`, `MODEL`, `YEAR`, `PRICE`, `MILEAGE`, `GEARBOX`, `STATUS`, `COLOR_IN`, `COLOR_OUT`, `BODY`, `FUEL`, `ABOUT`, `MAIN_PHOTO` FROM `ads` natural left join `cars` natural left join `ad_extras` WHERE `ads`.`USER_ID` = '2'


0 comments:

Post a Comment