If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Table optimization

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-11-06, 11:38
Konnor Konnor is offline
Registered User
 
Join Date: Mar 2006
Posts: 8
Table optimization

I have a table generated by

Code:
SELECT FlightID, NumSeats, Status FROM FlightBooking ORDER BY FlightID
Which gives me the result

FlightID | NumSeats | Status
-----------------------------------
1 | 2 | R
2 | 4 | H
2 | 2 | R
3 | 3 | H
4 | 2 | R
4 | 4 | H
4 | 1 | R
5 | 1 | R

I'd like to combine these records so it displays only one row with 4, 3, R

And also If i want to insert a row (e.g. 1, 2, R) it will be added to existing the row (to give 1, 4, R)

Many thanks,
Reply With Quote
  #2 (permalink)  
Old 03-11-06, 12:11
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
to combine your rows in your query results,
Code:
SELECT FlightID
     , sum(NumSeats) as total_NumSeats
     , Status 
  FROM FlightBooking 
GROUP BY FlightID, Status 
ORDER BY FlightID
to "add" a row to an existing row, don't use INSERT, use UPDATE
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On