2010-07-29 7 views
8

मैं मुझे के जीवन के लिए नहीं कर सकते यह पता लगाने क्यों इसMySQL त्रुटि 1248 (42000): हर ली गई तालिका का अपना उर्फ ​​

SELECT * FROM 
SELECT 
c.city_id, 
p.prop_ynow_id, 
p.propertyid, 
p.prop_add_value, 
p.name, 
picture, 
ifnull(p.address,'') as`location`, 
ifnull(city,'')as`city`, 
ifnull(ShortCut,'') as `state`, 
ifnull(p.zip,'') as `zip`, 
min(if(pr.minrent = 0,99999999,pr.minrent)) as minrent, 
max(pr.maxrent) as maxrent, 
'' as service, 
hood_id, 
ifnull(p.phone,'') as `phone`, 
latitude, 
longitude, 
min(CAST(pu.fullBath AS UNSIGNED)) as`minbath`, 
max(CAST(pu.fullBath AS UNSIGNED)) as`maxbath`, 
min(CAST(pu.Bed AS UNSIGNED)) as`minbed` , 
max(CAST(pu.Bed AS UNSIGNED)) as`maxbed`, 
'' as url, 
'' as source_id, 
'' as source_name, 
'' as addresscode, 
'' as citycode, 
'' as ctime, 
'' as paid, 
'' as similar_url, 
'' as created_at, 
'' as updated_at, 
'' as city_name, 
'' as service_listing_id 

FROM 
wiki_city_list c join propertyinfo p on c.city_id=p.city 
join ynow_rentwiki.Property_Unitlayout pu on p.prop_ynow_id=pu.P_Ident 
join (SELECT CAST(substring_index(if(Rent >0 ,Rent,RentLow),'.',1) AS UNSIGNED) as minrent, CAST(substring_index(if(Rent >0,Rent,Renthigh),'.',1) AS UNSIGNED) as maxrent,PRE_Ident,P_Ident,UNL_Ident,RTY_Ident from ynow_rentwiki.Property_rents where P_Ident in (3958, 4576, 4577) and (Rent!='' or (Rentlow!='' and Renthigh!=''))) as pr on pu.UNL_Ident=pr.UNL_Ident 
join state s on (p.state = s.stateid OR p.state = s.ShortCut) 
WHERE 
pu.Status='Active' 
and p.delete_date='0000-00-00' 

GROUP BY 
c.city_id, p.prop_ynow_id 

UNION 
SELECT 
c.city_id, 
p.prop_ynow_id, 
p.propertyid, 
p.prop_add_value, 
p.name, 
picture, 
ifnull(p.address,'') as`location`, 
ifnull(city,'')as`city`, 
ifnull(ShortCut,'') as `state`, 
ifnull(p.zip,'') as `zip`, 
min(if(pr.minrent = 0,99999999,pr.minrent)) as minrent, 
max(pr.maxrent) as maxrent, 
'' as service, 
hood_id, 
ifnull(p.phone,'') as `phone`, 
latitude, 
longitude, 
min(CAST(pu.fullBath AS UNSIGNED)) as`minbath`, 
max(CAST(pu.fullBath AS UNSIGNED)) as`maxbath`, 
min(CAST(pu.Bed AS UNSIGNED)) as`minbed` , 
max(CAST(pu.Bed AS UNSIGNED)) as`maxbed`, 
'' as url, 
'' as source_id, 
'' as source_name, 
'' as addresscode, 
'' as citycode, 
'' as ctime, 
'' as paid, 
'' as similar_url, 
'' as created_at, 
'' as updated_at, 
'' as city_name, 
'' as service_listing_id 

FROM 
wiki_city_list c join propertyinfo p on c.city_id=p.city 
join ynow_rentwiki.Property_Unitlayout pu on p.prop_ynow_id=pu.P_Ident 
join (SELECT CAST(substring_index(if(Rent >0 ,Rent,RentLow),'.',1) AS UNSIGNED) as minrent, CAST(substring_index(if(Rent >0,Rent,Renthigh),'.',1) AS UNSIGNED) as maxrent,PRE_Ident,P_Ident,UNL_Ident,RTY_Ident from ynow_rentwiki.Property_rents where P_Ident in (9744) and (Rent!='' or (Rentlow!='' and Renthigh!=''))) as pr on pu.UNL_Ident=pr.UNL_Ident 
join state s on (p.state = s.stateid OR p.state = s.ShortCut) 
WHERE 
pu.Status='Active' 
and p.delete_date='0000-00-00' 

GROUP BY 
c.city_id, p.prop_ynow_id 

UNION 
SELECT 
'' as prop_ynow_id, 
id as propertyid, 
0 as prop_add_value, 
t.name as name, 
'' as picture, 
t.address as location, 
t.city as city, 
s.ShortCut as state, 
t.zip as zip, 
CAST(REPLACE(REPLACE(t.price,'$',''),',','') as UNSIGNED) as minrent, 
'' as maxrent, 
t.service as service, 
'' as hood_id, 
'' as phone, 
t.latitude as latitude, 
t.longitude as longitude, 
t.bathrooms as minbath, 
'' as maxbath, 
t.bedrooms as minbed, 
'' as maxbed, 
t.url as url, 
t.source_id as source_id, 
t.source_name as source_name, 
t.addresscode as addresscode, 
t.citycode as citycode, 
t.ctime as ctime, 
t.paid as paid, 
t.similar_url as similar_url, 
t.created_at as created_at, 
t.updated_at as updated_at, 
SUBSTRING_INDEX(c.city_name,'_',1) as city_name,  
t.service_listing_id as service_listing_id 

FROM LBCPrimary.third_party_properties as t, LBCPrimary.wiki_city_list as c, LBCPrimary.state as s 
WHERE 
t.city in ('230') 
and 
address <> '' and 
t.city = c.city_id and 
c.city_state = s.stateid 

order by t.ctime 
desc 
limit 46 as a limit 0,50 
+0

आपकी क्वेरी चयन से चुनें * चयन से - क्या आप ब्रैकेट भूल सकते हैं? और चयन किया जाना चाहिए * से (चयन .... –

उत्तर

20

erroring है इसका मतलब है कि यह वास्तव में क्या कहते हैं होना आवश्यक है - प्रत्येक व्युत्पन्न तालिका चाहिए में उपनाम है। SELECT a.* FROM (SELECT ....)a

अद्यतन। यह आप के लिए काम करना चाहिए:

SELECT xxx.* FROM 
(
    SELECT .... 
    FROM .... 
    UNION 
    (
     SELECT .... 
     FROM ..... 
     LIMIT 46 
    ) 
    LIMIT 50 
)xxx 
+1

मुझे यकीन है कि तुम क्या मतलब है ... मैं इसे जोड़ने के लिए देखते हैं, लेकिन अब मैं पाने की कोशिश की त्रुटि 1064 (42000) नहीं कर रहा हूँ: आप में एक त्रुटि है आपका एसक्यूएल सिंटैक्स; मैनुअल की जांच करें जो आपके MySQL सर्वर संस्करण से संबंधित है, '0 050 के रूप में' सीमा के रूप में उपयोग करने के लिए सही वाक्यविन्यास के लिए '144 – Trace

+0

क्षमा करें, मुझे नहीं पता था कि आपकी तालिका में से एक में पहले से ही उपनाम है ए। एक अलग उपनाम का उपयोग करें - 'चुनें xxxx। * से (चयन करें ....) xxxx' – a1ex07

+0

और जब आप' चयन ... के लिए उपनाम का उपयोग करते हैं ... टी 1 जॉइन टी 2 जॉइन टी 3 में शामिल हों ... 'आपको ब्रैकेट में भी चयन करना चाहिए ('(चुनें ... टी 1 से जुड़ें टी 2 जॉइन टी 3 में शामिल हों ...) [एएस] ए')। यह 144 रुपये पर 'करीब 0,50 की सीमा के रूप में) पर शिकायत क्यों करता है " – a1ex07

4

आपकी क्वेरी के पहले लाइन

SELECT * FROM 

जो अनावश्यक होने के लिए (सभी तीन UNIONed प्रश्नों को पहले से ही चयन करें और खंड से शामिल के रूप में) प्रकट होता है।

इस अनावश्यक रेखा को हटाने से समस्या का समाधान होना चाहिए; वैकल्पिक रूप से, पहली पंक्ति के ठीक बाद ( जोड़ना, और अंत में ) QRYALIAS जोड़ना समस्या को हल करेगा।

संबंधित मुद्दे