Solved

SyBase SQL Syntax

Posted on 2013-10-25
4
654 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Google always has something new and amazing up its sleeve, and the most current thing that they have been working on is another step in the evolution of Google Search, from machine learning to its brilliant successor, deep learning.
February 24, 2017 — On February 23, Travis Ormandy, a vulnerability researcher at Google, reported on Twitter (https://twitter.com/taviso/status/834900838837411840) that massive stores of data have been leaked by CloudFlare, a company that provide…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 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