0

I'm trying to use the INNER JOIN functionality in my phpMyAdmin.

My query looks like this: SELECT * FROM ___Bookings INNER JOIN ___Origins ON ___Bookings.BOO_Origin=___Origins.ORI_Id WHERE BOO_Id=1.

The problem is at this step nothing is populated into the ___Origins table. So my query returns 0 row.

How to change my query to return a row even if I do not have the joined table populated ?

Also what's the difference between JOIN and INNER JOIN ?

Thanks so much.

Alex Howansky
  • 50,515
  • 8
  • 78
  • 98
  • `JOIN` and `INNER JOIN` are the same in mysql. https://stackoverflow.com/questions/565620/difference-between-join-and-inner-join . You want a `LEFT JOIN` in your case. – Roland Starke Oct 30 '17 at 16:10
  • `JOIN` and `INNER JOIN` are the same. You can try `LEFT JOIN` or `RIGHT JOIN`, depending on which table you want to show whether the other table has records or not. – Eric Oct 30 '17 at 16:10
  • Possible duplicate of [What is the difference between "INNER JOIN" and "OUTER JOIN"?](https://stackoverflow.com/questions/38549/what-is-the-difference-between-inner-join-and-outer-join) – Patrick Q Oct 30 '17 at 16:11

2 Answers2

0

Basically, you want to join the tables based on the data in the __BOOKINGS table. That's a job for LEFT JOIN, not INNER JOIN (which is the same as JOIN).

Refer here for more information on SQL Joins: http://www.sql-join.com/sql-join-types/

lurgan
  • 138
  • 6
0

There isn't a difference between Join and Inner Join (you can search for it also if this isn't enough).

For the other part - how can it return a row when there isn't one? If you need a response from PHP you can set something like

if ($query->rowCount() > 0) {
    echo $records;
}
else {echo "N";}

And in you other code just state if the response is "N" (or something else) do something or not do anything.

D.V.D.
  • 247
  • 2
  • 10