SELECT nom, cognom1, cognom2, nif FROM usuaris AS a LEFT JOIN persones AS b ON a.id_persona = b.id_persona LEFT JOIN entitats AS c ON b.id_entitat = c.id_entitat WHERE a.tipus LIKE 'agents'

SELECT nom, cognom1, cognom2, nif FROM usuaris AS a LEFT JOIN persones AS b ON a.id_persona = b.id_persona LEFT JOIN entitats AS c ON b.id_entitat = c.id_entitat WHERE a.tipus LIKE 'inspector'

SELECT nom, cognom1, cognom2, nif FROM usuaris AS a LEFT JOIN persones AS b ON a.id_persona = b.id_persona LEFT JOIN entitats AS c ON b.id_entitat = c.id_entitat WHERE a.tipus LIKE 'venedor'


SELECT nom, cognom1, cognom2, nif FROM clients AS a LEFT JOIN entitats AS b ON a.id_entitat = b.id_entitat LEFT JOIN persones AS c ON b.id_entitat = c.id_entitat WHERE b.tipus = 'persona'

SELECT rao_social, nif FROM clients AS a LEFT JOIN entitats AS b ON a.id_entitat = b.id_entitat LEFT JOIN empreses AS c ON b.id_entitat = c.id_entitat WHERE b.tipus = 'empresa'


SELECT nom, clau FROM comptes WHERE nom NOT LIKE 'admin';


SELECT superficie, caracteristiques, restriccions, preu, adresa FROM immobles AS a LEFT JOIN locals AS b ON a.id_local = b.id_local LEFT JOIN adreses AS d ON b.id_adresa = d.id_adresa WHERE b.tipus = 'immoble'

SELECT superficie, caracteristiques, restriccions, preu, adresa FROM immobles AS a LEFT JOIN locals AS b ON a.id_local = b.id_local LEFT JOIN adreses AS d ON b.id_adresa = d.id_adresa WHERE b.tipus = 'immoble' AND NOT EXISTS (SELECT * FROM contractes AS e WHERE b.id_local = e.id_local AND data_inici <= NOW() AND data_fi >= NOW())

SELECT superficie, caracteristiques, restriccions, preu, adresa FROM immobles AS a LEFT JOIN locals AS b ON a.id_local = b.id_local LEFT JOIN adreses AS d ON b.id_adresa = d.id_adresa WHERE b.tipus = 'immoble' AND EXISTS (SELECT * FROM contractes AS e WHERE b.id_local = e.id_local AND data_inici <= NOW() AND data_fi >= NOW())


SELECT superficie, caracteristiques, caracteristiques_polivalent, restriccions, preu, adresa FROM polivalents AS a LEFT JOIN locals AS b ON a.id_local = b.id_local LEFT JOIN adreses AS d ON b.id_adresa = d.id_adresa WHERE b.tipus = 'polivalent'

SELECT superficie, caracteristiques, caracteristiques_polivalent, restriccions, preu, adresa FROM polivalents AS a LEFT JOIN locals AS b ON a.id_local = b.id_local LEFT JOIN adreses AS d ON b.id_adresa = d.id_adresa WHERE b.tipus = 'polivalent' AND NOT EXISTS (SELECT * FROM contractes AS e WHERE b.id_local = e.id_local AND data_inici <= NOW() AND data_fi >= NOW())

SELECT superficie, caracteristiques, caracteristiques_polivalent, restriccions, preu, adresa FROM polivalents AS a LEFT JOIN locals AS b ON a.id_local = b.id_local LEFT JOIN adreses AS d ON b.id_adresa = d.id_adresa WHERE b.tipus = 'polivalent' AND EXISTS (SELECT * FROM contractes AS e WHERE b.id_local = e.id_local AND data_inici <= NOW() AND data_fi >= NOW())


SELECT superficie, caracteristiques, restriccions, preu, adresa FROM oficines AS a LEFT JOIN locals AS b ON a.id_local = b.id_local LEFT JOIN adreses AS d ON b.id_adresa = d.id_adresa WHERE b.tipus = 'oficina'

SELECT superficie, caracteristiques, restriccions, preu, adresa FROM oficines AS a LEFT JOIN locals AS b ON a.id_local = b.id_local LEFT JOIN adreses AS d ON b.id_adresa = d.id_adresa WHERE b.tipus = 'oficina' AND NOT EXISTS (SELECT * FROM contractes AS e WHERE b.id_local = e.id_local AND data_inici <= NOW() AND data_fi >= NOW())

SELECT superficie, caracteristiques, restriccions, preu, adresa FROM oficines AS a LEFT JOIN locals AS b ON a.id_local = b.id_local LEFT JOIN adreses AS d ON b.id_adresa = d.id_adresa WHERE b.tipus = 'oficina' AND EXISTS (SELECT * FROM contractes AS e WHERE b.id_local = e.id_local AND data_inici <= NOW() AND data_fi >= NOW())


SELECT superficie, caracteristiques, restriccions, preu, adresa FROM botigues_magatzem AS a LEFT JOIN locals AS b ON a.id_local = b.id_local LEFT JOIN adreses AS d ON b.id_adresa = d.id_adresa WHERE b.tipus = 'botiga_magatzem'

SELECT superficie, caracteristiques, restriccions, preu, adresa FROM botigues_magatzem AS a LEFT JOIN locals AS b ON a.id_local = b.id_local LEFT JOIN adreses AS d ON b.id_adresa = d.id_adresa WHERE b.tipus = 'botiga_magatzem' AND NOT EXISTS (SELECT * FROM contractes AS e WHERE b.id_local = e.id_local AND data_inici <= NOW() AND data_fi >= NOW())

SELECT superficie, caracteristiques, restriccions, preu, adresa FROM botigues_magatzem AS a LEFT JOIN locals AS b ON a.id_local = b.id_local LEFT JOIN adreses AS d ON b.id_adresa = d.id_adresa WHERE b.tipus = 'botiga_magatzem' AND EXISTS (SELECT * FROM contractes AS e WHERE b.id_local = e.id_local AND data_inici <= NOW() AND data_fi >= NOW())


SELECT data_inici, data_fi, d.nif AS nif_propietari, codi_local, h.nif AS nif_llogater FROM contractes AS a LEFT JOIN propietaris AS b ON a.id_propietari = b.id_propietari LEFT JOIN clients AS c ON b.id_client = c.id_client LEFT JOIN entitats AS d ON c.id_entitat = d.id_entitat LEFT JOIN locals AS e ON a.id_local = e.id_local LEFT JOIN llogaters AS f ON a.id_llogater = f.id_llogater LEFT JOIN clients AS g ON f.id_client = g.id_client LEFT JOIN entitats AS h ON g.id_entitat = h.id_entitat WHERE data_inici <= NOW() AND data_fi >= NOW()

SELECT data_inici, data_fi, d.nif AS nif_propietari, codi_local, h.nif AS nif_llogater FROM contractes AS a LEFT JOIN propietaris AS b ON a.id_propietari = b.id_propietari LEFT JOIN clients AS c ON b.id_client = c.id_client LEFT JOIN entitats AS d ON c.id_entitat = d.id_entitat LEFT JOIN locals AS e ON a.id_local = e.id_local LEFT JOIN llogaters AS f ON a.id_llogater = f.id_llogater LEFT JOIN clients AS g ON f.id_client = g.id_client LEFT JOIN entitats AS h ON g.id_entitat = h.id_entitat WHERE data_inici > NOW() OR data_fi < NOW()

SELECT data_inici, data_fi, d.nif AS nif_propietari, codi_local, h.nif AS nif_llogater FROM contractes AS a LEFT JOIN propietaris AS b ON a.id_propietari = b.id_propietari LEFT JOIN clients AS c ON b.id_client = c.id_client LEFT JOIN entitats AS d ON c.id_entitat = d.id_entitat LEFT JOIN locals AS e ON a.id_local = e.id_local LEFT JOIN llogaters AS f ON a.id_llogater = f.id_llogater LEFT JOIN clients AS g ON f.id_client = g.id_client LEFT JOIN entitats AS h ON g.id_entitat = h.id_entitat


akordarse:prefierencies llogaters