If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > if else cond for select statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-07-09, 01:31
reddy761 reddy761 is offline
Registered User
 
Join Date: Oct 2009
Posts: 1
if else cond for select statement

Hi
I need if else cond for my sql,
I have ACCOUNT is my master table contains account id is the column for comparing for other tables.

I have other two child tables contains account id column in both the tables.

my data will be there in my master table all account id information.
similarly my data will be the in my child tables either one of them either first child table or second child table.

how can i write my sql select query for getting the data by comparing account id

tryign to this way..plz correct me

CASE WHEN(INNER JOIN CRMDETAILS ON CRMDETAILS.ACID = ADVACDETAIL.ACID)
THEN
CRMDETAILS.CRMSECUID AS CRMSECUID,
CRMDETAILS.DTOFISSUE AS DTOFISSUE,
CRMDETAILS.DTOFMATURITY AS DTOFMATURITY,
CRMDETAILS.CURRENTVALUE AS CURRENTVALUE,
ELSE
PRIMARY_SECURITY.CRMSECUID AS CRMSECUID,
PRIMARY_SECURITY.CURRENTVALUE AS CURRENTVALUE,
PRIMARY_SECURITY.DTOFISSUE AS DTOFISSUE,
PRIMARY_SECURITY.DTOFMARTURITY AS CURRENTVALUE


Thanks
Venkatesh
Reply With Quote
  #2 (permalink)  
Old 10-07-09, 14:19
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
try looking at union
Reply With Quote
  #3 (permalink)  
Old 10-07-09, 17:34
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
try two LEFT OUTER JOINs
Code:
SELECT COALESCE(crmdetails.crmsecuid   
               ,primary_security.crmsecuid    ) AS crmsecuid        
     , COALESCE(crmdetails.dtofissue        
               ,primary_security.dtofissue    ) AS dtofissue   
     , COALESCE(crmdetails.dtofmaturity     
               ,primary_security.dtofmaturity ) AS dtofmaturity
     , COALESCE(crmdetails.currentvalue     
               ,primary_security.currentvalue ) AS currentvalue
  FROM advacdetail
LEFT OUTER
  JOIN crmdetails 
    ON crmdetails.acid = advacdetail.acid
LEFT OUTER
  JOIN primary_security
    ON primary_security.acid = advacdetail.acid
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On