Jump to content


Photo

LEFT JOIN


  • Please log in to reply
1 reply to this topic

#1 baber_abbasi

baber_abbasi
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts
  • LocationPakistan

Posted 07 November 2003 - 07:13 PM

I have edited an existing code to my own having LEFT JOIN feature in it. I am getting errors while replacing table name.

EXISTING CODE
$tablepre = \"calendar\";
$sql = \"SELECT id, y, m, d, title, text, TIME_FORMAT(start_time, \'%l:%i %p\') AS stime, TIME_FORMAT(end_time, \'%l:%i %p\') AS etime, \" . $tablepre . \"users.uid, fname, lname FROM \" . $tablepre . \"mssgs LEFT JOIN \" . $tablepre . \"users ON (\" . $tablepre . \"mssgs.uid=\" . $tablepre . \"users.uid) WHERE id = \" . $id;

I need to replace [ \" . $tablepre . \"users.uid ] with [ clients.uid ]

Thankx in advance.
Baber N Abbasi

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 07 November 2003 - 08:26 PM

It\'s alot easier to use aliases for table names when joining tables. That way you only have one occurence of each tablename

eg (partial query as sample)

SELECT a.id, a.y, a.m, a.d, a.title, b.name
FROM calendarmssgs a INNER JOIN calendarusers b
ON a.uid = b.uid
WHERE a.id = $id

hth
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users