All pastes #396614 Raw Edit

Stuff

public text v1 · immutable
·published 2007-03-15 21:52 UTC
rendered paste body
SELECT * FROM (
	(SELECT 
			rownum as row_id, usr.usr_id, brokerage_firm.firm_name, usr.first_name, usr.last_name, apt_finder_new_buy_search2.source_id, apt_finder_new_buy_search2.listing_id, apt_finder_new_buy_search2.type_2, apt_finder_new_buy_search2.type_3, apt_finder_new_buy_search2.type_4, apt_finder_new_buy_search2.type_7, apt_finder_new_buy_search2.bldg_id, apt_finder_new_buy_search2.name_address_display, 
			apt_finder_new_buy_search2.unit, to_char(apt_finder_new_buy_search2.when_added, 'MM-DD-YYYY') as date_added, apt_finder_new_buy_search2.last_update, apt_finder_new_buy_search2.bedroom_display, apt_finder_new_buy_search2.price, apt_finder_new_buy_search2.square_feet,
			hood.hood_name, hood.hood_id
		FROM 
		 	apt_finder_new_buy_search2, building, hood, usr_listing_history history, usr, brokerage_firm, broker_profile 
		WHERE 
			(apt_finder_new_buy_search2.when_added > SYSDATE - 120 OR apt_finder_new_buy_search2.last_update > SYSDATE - 120) AND 
			apt_finder_new_buy_search2.listing_id = history.listing_id AND 
			broker_profile.usr_id = history.usr_id AND 
			brokerage_firm.brokerage_id = broker_profile.brokerage_id AND 
			usr.usr_id = history.usr_id AND 
			history.listing_id = apt_finder_new_buy_search2.listing_id AND 
			apt_finder_new_buy_search2.source_id != 'broker' AND 
			apt_finder_new_buy_search2.bldg_id = building.building_id AND 
			building.hood_id = hood.hood_id 
		ORDER BY 
			apt_finder_new_buy_search2.price DESC) 
	UNION 
	
	(SELECT 
				rownum as row_id, usr.usr_id, brokerage_firm.firm_name, usr.first_name, usr.last_name, apt_finder_new_buy_search2.source_id, apt_finder_new_buy_search2.listing_id, apt_finder_new_buy_search2.type_2, apt_finder_new_buy_search2.type_3, apt_finder_new_buy_search2.type_4, apt_finder_new_buy_search2.type_7, apt_finder_new_buy_search2.bldg_id, apt_finder_new_buy_search2.name_address_display, 
				apt_finder_new_buy_search2.unit, to_char(apt_finder_new_buy_search2.when_added, 'MM-DD-YYYY') as date_added, apt_finder_new_buy_search2.last_update, apt_finder_new_buy_search2.bedroom_display, apt_finder_new_buy_search2.price, apt_finder_new_buy_search2.square_feet,
				hood.hood_name, hood.hood_id
			FROM 
			 	apt_finder_new_buy_search2, building, hood, nytlistings history, usr, brokerage_firm, broker_profile 
			WHERE 
				(apt_finder_new_buy_search2.when_added > SYSDATE - 120 OR apt_finder_new_buy_search2.last_update > SYSDATE - 120) AND 
				apt_finder_new_buy_search2.listing_id = history.listing_id AND 
				broker_profile.usr_id = usr.usr_id  AND 
				brokerage_firm.brokerage_id = broker_profile.brokerage_id AND 
				usr.usr_id = history.usr_in_id (+) AND 
				history.listing_id = apt_finder_new_buy_search2.listing_id AND 
				apt_finder_new_buy_search2.source_id != 'broker' AND 
				apt_finder_new_buy_search2.bldg_id = building.building_id AND 
				building.hood_id = hood.hood_id 
			ORDER BY 
				apt_finder_new_buy_search2.price DESC)
)