Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Dynamically Select From 2 Tables Based On Id, dynamically select from 2 tables based on id
eskimmer
post Aug 16 2007, 01:40 PM
Post #1


Newbie [Level 1]
*

Group: Members
Posts: 21
Joined: 15-August 07
Member No.: 48,203



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 tables
php 5.2
Go to the top of the page
 
+Quote Post
Stenno
post Oct 11 2007, 04:14 PM
Post #2


Newbie [Level 1]
*

Group: [HOSTED]
Posts: 21
Joined: 29-September 07
Member No.: 50,836



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

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


or

CODE
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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Creatin Tables In Mysql(4)
  2. Storing Session Variables Generated Dynamically(3)
  3. Compare 2 List Of User Ids From Different Tables(1)
  4. Php And Irc(5)
  5. Remove A Value From A Php Array Based On Its Value(5)
  6. Looking For Command Line Based Sql Modification(1)
  7. Creating Something With Co-ordinates With Php.(12)
  8. Sending E-mails Based On Intervals?(7)


 



- Lo-Fi Version Time is now: 30th August 2008 - 02:17 AM