astralaaron Posted December 6, 2010 Share Posted December 6, 2010 example table 1 `users` :| user_id | user_name | photo_url |example table 2 `user_mail` :| message_id | user_id | message |example sql: SELECT `user_mail`.`message_id`, `user_mail`.`user_id`, `user_mail`.`message`, `users`.`user_id`, `users`.`user_name` FROM `user_mail` LEFT JOIN `users` ON `users`.`user_id = `user_mail`.`user_id` WHERE `user_mail`.`message_id`=$msg_id --basically I would like to be able to select * from the user_mail table, then specify which fields from the users table I want to join on.my real tables have many more fields than these and I'm joining multiple ones. I've been specifying every field and it seems like there should be an easier way. Link to comment Share on other sites More sharing options...
boen_robot Posted December 6, 2010 Share Posted December 6, 2010 If the field names in both tables are the same, as is in this case, you can use USING(), like: LEFT JOIN `users` USING(`user_id`) Link to comment Share on other sites More sharing options...
astralaaron Posted December 6, 2010 Author Share Posted December 6, 2010 Nice, if that joins the whole users table then that would work great. thanks.EDIT: tried it, works perfect, thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.