Jump to content

Showing Indirectly Related field


prophecym

Recommended Posts

Please see below for table details.

 

I have these tables have relations in each other and I need a report using INNER JOIN. I figured out the most but there is one thing I couldn't.

 

There is CompanyName field in the Companies Table I need to show in the report but it is only related to Contacts Table by ContactID. How can I get it to show on my report? I hope I made myself clear.

 

Here is the SQL sytnax.

 

SELECT accounttypes.accounttype, contacts.firstname, contacts.lastname, contacts.namesuffix, contacts.emailname, contacts.workphone, speakers.programtrack, speakers.recruitedby
FROM regcontacts
INNER JOIN accounttypes ON regcontacts.accounttypeid = accounttypes.accounttypeid
INNER JOIN contacts ON regcontacts.contactid = contacts.contactid
INNER JOIN speakers ON regcontacts.registrationid = speakers.registrationid
WHERE regcontacts.eventid =  '235'
AND regcontacts.participationid =  '3'

 

 

table RegContacts fields :

AccountTypeID

ContactID

RegistrationID


table AccountTypes fields :

AccountTypeID


table Contacts fields :

ContactID

CompanyID


table Speakers fields :

RegistrationID


table Companies fields :

ContactID

CompanyID

Link to comment
Share on other sites

It took me 30 seconds to figure it out. If i had spent my time on thinking, instead of typing all colorful, fancy shmancy topic, i would have created my report. Well what's done is done.

 

Here is the right syntax.

SELECT accounttypes.accounttype, contacts.firstname, contacts.lastname, contacts.namesuffix, contacts.emailname, contacts.workphone, speakers.programtrack, speakers.recruitedby, companies.companyname
FROM regcontacts
INNER JOIN accounttypes ON regcontacts.accounttypeid = accounttypes.accounttypeid
INNER JOIN contacts ON regcontacts.contactid = contacts.contactid
INNER JOIN speakers ON regcontacts.registrationid = speakers.registrationid
INNER JOIN companies ON contacts.companyid = companies.companyid
WHERE regcontacts.eventid =  '235'
AND regcontacts.participationid =  '3'
LIMIT 0 , 30

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.