Solved

SQL Syntax

Posted on 2014-02-20
2
444 Views
Last Modified: 2014-02-20
Hey guys,

I have 2 tables....Trans and TransDetails

I am trying to select the (TransNum)'s from the Trans table where they only have 1 record in the TransDetail table and that record's ProdID is = 111.


Trans
TransNum        FinalTotal
1                        25
2                        15
3                        73
4                        34
5                        98



TransDetails
Unique ID              TransNum            ProdID
1                            1                             111
2                            1                             259
3                            1                             854
4                            2                             111
5                            3                             111
6                            3                             665
7                            3                             811
8                            3                             911
9                            4                             111
10                          4                             654
11                          4                             785
12                          4                             215
13                          4                             614
14                          5                             111

In this example I want the query to return TransNum 2 and 5.


SyBase SQL Anywhere v10
0
Comment
Question by:triphen
2 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 39876047
Select Transnum from Trans
where TransNum in ( Select TransNum from TransDetails
Group by TransNum having Count(*) = 1)
0
 

Author Closing Comment

by:triphen
ID: 39876067
You rock!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

12 Experts available now in Live!

Get 1:1 Help Now