[dba-SQLServer] Newbie needs help with select statement- part 2

jean-paul jnatola at hotmail.com
Tue Feb 3 13:08:30 CST 2009



turns out i need to do 2 different queries
now that I have this-

comes the scary part- how would  IMPORT - 

I had no problems importing just into contacts, tested it with a csv and it went right in-
the key is to get source_codes and org_types to match the records

one for source codes;

SELECT contacts.*,
     contacts_source_codes.source_code
FROM contacts
LEFT JOIN switchboard
     ON switchboard.table_left_id = contacts.id
         AND switchboard.table_left = 'contacts'
LEFT JOIN contacts_source_codes
     ON contacts_source_codes.id = switchboard.table_right_id
WHERE switchboard.table_right = 'contacts_source_codes'
     AND contacts_source_codes.id IS NOT NULL
ORDER BY contacts.last_name, contacts.first_name


one for org types;

SELECT contacts.*,
     contacts_organization_types.organization_type
FROM contacts
LEFT JOIN switchboard
     ON switchboard.table_left_id = contacts.id
         AND switchboard.table_left = 'contacts'
LEFT JOIN contacts_organization_types
     ON contacts_organization_types.id = switchboard.table_right_id
WHERE switchboard.table_right = 'contacts_organization_types'
     AND contacts_organization_types.id IS NOT NULL
ORDER BY contacts.last_name, contacts.first_name

 

 

 

 

 

 

 

 

 

 

Jean-Paul Natola

 




> Date: Mon, 2 Feb 2009 14:35:08 -0600
> To: dba-sqlserver at databaseadvisors.com
> From: robert at webedb.com
> Subject: Re: [dba-SQLServer] Newbie needs help with select statement
> 
> In order to "link" the tables together,
> they have to have a column in common
> between them.
> 


_________________________________________________________________
Hotmail® goes where you go. On a PC, on the Web, on your phone. 
http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208 


More information about the dba-SQLServer mailing list