Solved

SyBase SQL Syntax

Posted on 2013-10-25
4
644 Views
Last Modified: 2013-10-25
Hey guys,
 
I have 2 tables using SyBase SQL Anywhere 10
Employee Table
EmpNum
Firstname
Lastname
 
Sales Table
Transact
WhoStart (EmpNum)
WhoClosed   (EmpNum)
 
I want to return the transaction number and the first name’s of the employee who started and closed the sale. Usually the person who starts and closes is the same, but sometimes it’s not.
 
Help?
0
Comment
Question by:triphen
  • 2
4 Comments
 
LVL 26

Assisted Solution

by:wilcoxon
wilcoxon earned 250 total points
ID: 39601768
This should do what you want...
select s.Transact, es.Firstname, ec.Firstname
from Sales s, Employee es, Employee ec
where s.WhoStart = es.EmpNum
and s.WhoClosed = ec.EmpNum

Open in new window

0
 
LVL 48

Accepted Solution

by:
PortletPaul earned 250 total points
ID: 39601812
I'd prefer to see ANSI join syntax used, the following is the equivalent of the prior comment:
SELECT
        s.Transact
      , es.Firstname AS StartByName
      , ec.Firstname AS ClosedByName
FROM Sales s
INNER JOIN Employee AS es ON s.WhoStart = es.EmpNum
INNER JOIN Employee AS ec ON s.WhoClosed = ec.EmpNum /* but might need LEFT JOIN ?? */
;

Open in new window

whilst it may be unlikely, if there is any chance that a record in that Sales tables does not have a value for WhoClosed, then you would want to use a LEFT JOIN

(I do hope you would always have values in WhoStart, but if some are missing then it too might need a left join)
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 39601850
Tangent...  Personally I *HATE* the ANSI join syntax.  I find it much harder to read than the "old" join syntax.  For this query, it's not bad but, as it gets more complex, the less I like ANSI joins.
0
 

Author Closing Comment

by:triphen
ID: 39601907
Thanks guys! I ended up using the ANSI join syntax.

left outer join dba.employee as es
on es.empnum = header.whostart

left outer join dba.employee as ec
on ec.empnum = header.whoclose
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now