Jump to content

short hand for sql


astralaaron

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...