SQL Query (need help)

Results 1 to 2 of 2

Thread: SQL Query (need help)

  1. #1
    Join Date
    Dec 1969

    Default SQL Query (need help)

    Hi,<BR><BR>I am having problem with SQL statement which should fetch me COMPANY_ID,COMP_NAME,PERS_NAME,PERS_FAM_NAME from three tables.<BR><BR>SAL_SPERS (SP_ID,SP_COMP_ID) holds the information about SALES PERSONS <BR><BR>GLB_COMP(COMP_ID,COMP_NAME,COMP_ADDR) holds COMPANY information, <BR><BR>and GLB_PERSON (PERS_ID,PERS_NAME,PERS_FAM_NAME,PERS_ADDR).<BR><B R>the DB is like this.<BR><BR>SAL_SPERS <BR><BR>SP_ID SP_COMP_ID<BR><BR>1000 100<BR>1001 100<BR>1002 200<BR>1003 &#060;null&#062;<BR>1004 300<BR><BR>GLB_COMP<BR><BR>COMP_ID COMP_NAME COMP_ADDR<BR>100 xyz #21<BR>200 pqr #34<BR>300 lmn #45<BR><BR><BR>GLB_PERSON<BR><BR>PERS_ID PERS_NAME PERS_FAM_NAME PERS_ADDR<BR>1000 michael d&#039souza ca<BR>1001 george bird ny<BR>1002 jonathan edward xy<BR>1003 morris mono mm<BR>1004 john king pp<BR><BR>how we can retrieve all records,if SP_COMP_ID is null it is not fetching all records.<BR><BR>the output should be<BR><BR>COMP_ID COMP_NAME SP_ID PERS_NAME PERS_FAM_NAME<BR>100 xyz 1000 michael D&#039souza <BR>100 xyz 1001 george bird<BR>200 pqr 1002 jonathan edward<BR>null null 1003 morris mono<BR>300 lmn 1004 john king<BR><BR>i am using SQL server 7.0<BR>tried with JOIN,hope the syntax was not correct.<BR>can any one help me?<BR><BR>thanks<BR>

  2. #2
    Join Date
    Dec 1969

    Default You need an OUTER JOIN

    Also known as either a LEFT JOIN or RIGHT JOIN (depending on how you do it).<BR><BR>I&#039m not a SQL Server person, so I hope somebody else can help you. Why not ask in the DATABASE forum instead of here in the general forum? Ask how to set up an OUTER JOIN to do this.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts