Understanding INNER JOIN

Have used inner join before but trying to get my head round columns with different names.

Trying to call the following information in a query but can’t seem to get it right when using the inner join to cross reference tables.

SELECT * FROM booked_open INNER JOIN courses ON booked_open.cidx = courses.idx WHERE booked_open.didx=$course;

I need all information called from booked_open ($var->name, $var->tel, etc)

The booked_open.cidx reference number matches the courses.idx number and just need to pull a single title name from the courses table into the booked_open query.

I am trying to get courses.title into the query so i can access it as $var->title

I have used inner join before but the column names between these two tables are different so I am struggling to understand the link and how you use inner join in this instance.

Many thanks

are you sure booked_open has two columns called cidx and didx??

try it like this –

SELECT booked_open.* 
     , courses.title
  FROM courses
INNER 
  JOIN booked_open 
    ON booked_open.cidx = courses.idx 
 WHERE courses.idx = $course;

Yes the two columns are correct.
Your script worked well, thankyou.

I think it appeared to be the first call of Select From that was the issue as you have used it in a diiferent way and it has solved the issue. Lesson learnt, many thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.