Visualizzazione dei risultati da 1 a 2 su 2

Discussione: Join con 3 tabelle

  1. #1

    Join con 3 tabelle

    ciao a tutti ho questa select join con 3 tabelle ovviamente mi va in errore ... dove sbaglio

    Codice PHP:
    if ordine "" then strSQL "SELECT "&_
    "* FROM hotel_es as h LEFT JOIN tipo_strutture as t ON "&_
    "h.id = t.hotel_id LEFT JOIN ranking ON h.id = ranking.hotel_id where (h.city_hotel like '"&replace(nomecitta,"'","''")&"%' or h.city_preferred like '"&replace(nomecitta,"'","''")&"%') and (t.hoteltype_id in (" struttura2 ") or t.hoteltype_id IS NULL) order by ranking.review_score asc,h.id" 
    errore:
    Microsoft JET Database Engine (0x80040E14)
    Errore di sintassi (operatore mancante) nell'espressione della query 'h.id = t.hotel_id LEFT JOIN ranking ON h.id = ranking.hotel_id'.

    praticamente questa è la query originale che funziona:

    Codice PHP:
    "* FROM hotel_es as h LEFT JOIN tipo_strutture as t ON "&_
                  
    "h.id = t.hotel_id where (h.city_hotel like '"&replace(nomecitta,"'","''")&"%' or h.city_preferred like '"&replace(nomecitta,"'","''")&"%') and (t.hoteltype_id in (" struttura2 ") or t.hoteltype_id IS NULL) order by h.minrate asc,h.id 
    praticamente quello che vorrei fare è ordinare al posto di by h.minrate mettere by ranking.review_score



  2. #2
    ok sembra funzionare così:

    Codice PHP:
    "hotel_es.id, hotel_es.name, hotel_es.address, hotel_es.zip, hotel_es.city_hotel, hotel_es.class, hotel_es.minrate, hotel_es.nr_rooms, hotel_es.photo_url, hotel_es.desc_en, hotel_es.desc_es, hotel_es.desc_it, "&_
                
    "tipo_strutture.hoteltype_id, ranking.review_score, ranking.review_nr, ranking.preferred "&
                
    "FROM "&_
                
    "(hotel_es LEFT JOIN tipo_strutture ON hotel_es.id=tipo_strutture.hotel_id) LEFT JOIN ranking ON hotel_es.id=ranking.hotel_id "&_
                  
    " where (hotel_es.city_hotel like '"&replace(nomecitta,"'","''")&"%' or hotel_es.city_preferred like '"&replace(nomecitta,"'","''")&"%') and (tipo_strutture.hoteltype_id in (" struttura2 ") or tipo_strutture.hoteltype_id IS NULL) order by ranking.preferred DESC,hotel_es.id" 

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.