473,434 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

Flat query

CroCrew
564 Expert 512MB
Hello Everyone,

First I would like to thank anyone that helps me with this question.

I am looking for a query that will return one row of data for each person based on the “IssuedTo” column. Let me explain:

I have two tables and the first is the “Tickets” table and the second is the “People” table. Below are the two tables.

Tickets:
Expand|Select|Wrap|Line Numbers
  1. KeyID IssuedTo Sold  
  2. 1     1        False        
  3. 2     3        False        
  4. 3     1        False        
  5. 4     2        False        
  6. 5     2        False        
  7. 6     3        False        
  8. 7     3        False        
  9. 8     2        False        
  10. 9     1        False        
  11. 10    3        False        
  12.  
People:
Expand|Select|Wrap|Line Numbers
  1. KeyID Name
  2. 1     Sam
  3. 2     Kim
  4. 3     Dave
  5.  

This is the query that I have so far:
Expand|Select|Wrap|Line Numbers
  1. SELECT b.Name as 'Ticket Owner', a.KeyID as 'Lowest Ticket#', a.KeyID as 'Highest Ticket#' FROM Tickets a JOIN People b ON (a.IssuedTo = b.KeyID) 
  2.  
Is it possible to get this results from a single query?:
Expand|Select|Wrap|Line Numbers
  1. Ticket Owner Lowest Ticket# Highest Ticket#
  2. Sam          1              9
  3. Dave         2              10
  4. Kim          4              8
  5.  
oh, the ticket number is the KeyId field in the Tickets table.


Again; thanks for the help,
CroCrew~
Aug 24 '10 #1

✓ answered by ck9663

Got it...The KeyID got me confused. The KeyId on your table is the same name as your KeyId on your persons table. Which, on first glance, tells me it's the link on those tables.

Try something like

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT IssuedTo, min(KeyId) as LowestTicket, max(KeyId) as HighestTicket
  3. from Tickets t
  4. inner join Person p on t.IssuedTo = p.KeyId
  5. group by IssuedTo
  6.  
This is a INNER JOIN. Which means only tickets with assigned person ID that exists on your persons table will be returned. Make it a LEFT JOIN as necessary.

Happy Coding!!!

~~ CK

4 1694
ck9663
2,878 Expert 2GB
Could you explain how you got those numbers? Are those counts? min? max?

~~ CK
Aug 24 '10 #2
CroCrew
564 Expert 512MB
I think your asking about the "Lowest Ticket#" and "Highest Ticket#" right?

The numbers come from the Tickets table's KeyID field. The KeyID fields are unique auto incrementing fields starting with the number 1.

So for the person Sam he has three records in the tickets table. row 1, row 3, and row 9. 1 would be his "Lowest Ticket#" and 9 would be his"Highest Ticket#".

understand?

Thanks for looking at my question.

CroCrew~
Aug 24 '10 #3
ck9663
2,878 Expert 2GB
Got it...The KeyID got me confused. The KeyId on your table is the same name as your KeyId on your persons table. Which, on first glance, tells me it's the link on those tables.

Try something like

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT IssuedTo, min(KeyId) as LowestTicket, max(KeyId) as HighestTicket
  3. from Tickets t
  4. inner join Person p on t.IssuedTo = p.KeyId
  5. group by IssuedTo
  6.  
This is a INNER JOIN. Which means only tickets with assigned person ID that exists on your persons table will be returned. Make it a LEFT JOIN as necessary.

Happy Coding!!!

~~ CK
Aug 24 '10 #4
Jerry Winston
145 Expert 100+
Just GROUP BY Person.Name and use MIN and MAX functions. Am I missing something in your requirement?
Aug 24 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Larry Rekow | last post by:
I have a report that's created each day as a flat textfile. Because I came from the Access world, I created a macro that imports it with a schema that gives meaningful names to the various...
4
by: amywolfie | last post by:
I have a curious mission: I converted an Excel file to a relational Access 2002 database, and now I have to export data back to IT as a FLAT .csv file. I know how to create many records from...
5
by: Shibu | last post by:
Hi, I have a situation where I need to convert business objects to a flat table. The reverse is also required. I am using c# and Oracle ODP. I am looking for an easier method to do the below...
3
by: Ash | last post by:
Hi, Using this sample XML ...... <Data> <House> <Location> London </Location> <Type> Detached </Type> <Value> 200,000 </Value>
7
by: ajay | last post by:
Hi I need to read data from flat files in memory and execute SQL query on the in-memory data. I do not have an option of using a database and I am using c# .Net to build my application. Does...
3
by: Porkapalooza | last post by:
I've inherited a database that had a single flat table holding client and policy information. The policy information included individual fields for estimated commissions (i.e. "Comm 99"; "Comm...
1
by: new | last post by:
I have data for each week in a single table. I need to export this data to a separate flat file for each week. Any ideas? DB2 SQL Query export to flat files as a function of data on each record
1
by: TF | last post by:
This group came through for me last time so here we go again. My page shows paint colors, brand name, product code, etc in a gridview with the background matching the paint color. Several links on...
5
by: Gorilla3D | last post by:
I've writing my own flat file database.. well table-based pure php code, PhpSimpleDb but I was looking into some bench marking so was wonder if anyone knew any other flat-file php db's out there. ...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.