Jump to content
xisto Community
Sign in to follow this  
eskimmer

Dynamically Select From 2 Tables Based On Id dynamically select from 2 tables based on id

Recommended Posts

hi there,im working on a performance request system, and i have three tables that im working with right now. the performances table holds the info about the performance (date, times, status, etc.), and has two columns, org_type and org_id, which both hold an int value to tell me where the organization info is. there are two org types which have respective tables, because we collect different information based on the type of org that is registering. is there any way to select info from all three tables (dynamically selecting between the two org tables based on org_type, then selecting the proper org info based on org_id) in one query?what im using:mysql 5.0, MyISAM tablesphp 5.2

Share this post


Link to post
Share on other sites

Yes there is away to select info from mutiple tables out your database. This is the way:

SELECT p.date, p.time, o.name, o.blabla FROM `preformance` AS p AND `organization` AS o WHERE o.id = p.org_id;

or

SELECT preformance.date, preformance.time, organization.name, organization.blabla FROM `preformance` AND `organization` WHERE organization.id = preformance.org_id;

But as you can see the first method is way more efficient. Good luck with it

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.