MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 22nd, 2012, 11:41 AM
Johnathan Johnathan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 6 Johnathan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 5 m 58 sec
Reputation Power: 0
How To Select Max (What Is Wrong In My Query)

Hello I'm trying to select max price, i keep getting 0 results when i should be getting some. Any ideas on what I did wrong?

The query should query a list of sites, find all of their ticket types and then display the most expensive ticket type only and the price of that ticket.

Thank you for any help! I'm very new to SQL,

Code:
select node_code, name, tt.code, price, effective_date, district_code
from node n, tickettype_price_set tps, tickettype_price tp, ticket_type tt, site s
where n.id = site_id
and s.id = n.id
and node_type = 'backoffice'
and tps.tickettype_price_set_id = tp.tickettype_price_set_id
and tt.id = tickettype_id
and tt.deleted = 0
and node_name not like '%CLOSED%'
--and tt.code in (0189)
--and tt.name like '%ADRCM%'
--and node_code in ()
			
			
and price = (select max(price) 
			from tickettype_price, node
			where n.id = site_id
			and s.id = n.id)
			
		
		
			
order by node_code, name

Reply With Quote
  #2  
Old July 22nd, 2012, 05:12 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,361 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 5 h 23 m 30 sec
Reputation Power: 4140
hello Johnathan

please indicate which table each of the columns belongs to that is marked in red ...
Code:
select node_code, name, tt.code, price, effective_date, district_code
from node n, tickettype_price_set tps, tickettype_price tp, ticket_type tt, site s
where n.id = site_id
and s.id = n.id
and node_type  = 'backoffice'
and tps.tickettype_price_set_id = tp.tickettype_price_set_id
and tt.id = tickettype_id
and tt.deleted = 0
and node_name  not like '%CLOSED%'
and price  = (select max(price) 
			from tickettype_price, node
			where n.id = site_id
			and s.id = n.id)		
order by node_code, name
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > How To Select Max (What Is Wrong In My Query)

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap