I have
SELECT
servisler.geo_location,
servisler.ADRES_MERKEZ,
servisler.ADRES_ILCE,
servisler.ADRES_IL,
servisler.FIRMA_UNVANI,
servisler.ADRES_ISTEL,
servisler.YETKILI_ADISOYADI,
urun_gruplari.GRUP_ADI
FROM
servisler
INNER JOIN urun_gruplari ON kullanici_cihaz.URUN_GRUP_NO= urun_gruplari.RECNO
INNER JOIN kullanici ON kullanici.SERVIS_RECNO = servisler.RECNO
INNER JOIN kullanici_cihaz ON kullanici.RECNO = kullanici_cihaz.KUL_RECNO AND kullanici_cihaz.URUN_GRUP_NO = urun_gruplari.RECNO
where kullanici.kullanici = 'MAR.EDI.003'
but it says
[Err] 1054 - Unknown column 'kullanici_cihaz.URUN_GRUP_NO' in 'on clause'
enen though the column exits. What is its problem?
schema
Server version: 5.1.33-community-log
I think this is because you're using the kullanici_cihaz table in your ON clause, and that before this table is linked.
Try to rearrange your INNER JOIN :
SELECT
servisler.geo_location,
servisler.ADRES_MERKEZ,
servisler.ADRES_ILCE,
servisler.ADRES_IL,
servisler.FIRMA_UNVANI,
servisler.ADRES_ISTEL,
servisler.YETKILI_ADISOYADI,
urun_gruplari.GRUP_ADI
FROM
servisler
INNER JOIN kullanici ON kullanici.SERVIS_RECNO = servisler.RECNO
INNER JOIN kullanici_cihaz ON kullanici.RECNO = kullanici_cihaz.KUL_RECNO
INNER JOIN urun_gruplari ON kullanici_cihaz.URUN_GRUP_NO= urun_gruplari.RECNO
WHERE
kullanici.kullanici = 'MAR.EDI.003'
EDIT
You also have some 'loop inner join', I removed it :
INNER JOIN urun_gruplari ON kullanici_cihaz.URUN_GRUP_NO= urun_gruplari.RECNO
INNER JOIN kullanici_cihaz ON kullanici.RECNO = kullanici_cihaz.KUL_RECNO AND kullanici_cihaz.URUN_GRUP_NO = urun_gruplari.RECNO
Because kullanici.SERVIS_RECNO does not exist when you join the tables: servisler, urun_gruplari. Join table kullanici first before joining urun_gruplari.
SELECT servisler.geo_location,
servisler.ADRES_MERKEZ,
servisler.ADRES_ILCE,
servisler.ADRES_IL,
servisler.FIRMA_UNVANI,
servisler.ADRES_ISTEL,
servisler.YETKILI_ADISOYADI,
urun_gruplari.GRUP_ADI
FROM servisler
INNER JOIN kullanici
ON kullanici.SERVIS_RECNO = servisler.RECNO
INNER JOIN urun_gruplari
ON kullanici_cihaz.URUN_GRUP_NO= urun_gruplari.RECNO
INNER JOIN kullanici_cihaz
ON kullanici.RECNO = kullanici_cihaz.KUL_RECNO AND
kullanici_cihaz.URUN_GRUP_NO = urun_gruplari.RECNO
where kullanici.kullanici = 'MAR.EDI.003'
Related
I'm having problems with a MySQL Query. I have read a lot of the currently answered threads, following a lot of examples but I have not been able to solve my trouble so I come to you for help. Thanks in advance.
I have this query:
SELECT ventas.*,
clientes.nombre AS CLIENT_NOMBRE,
clientes.telefono AS TELEFONO,
users.nombre AS USERNAME,
canales_ventas.nombre AS CAN_VENTA,
estados_venta.nombre AS ESTADOS,
metodos_pago.nombre AS MET_PAGO,
canales_entrega.nombre AS CAN_ENTREGA,
canales_entrega.categoria AS CAN_ENTREGA_CAT,
COALESCE(perc.qty,0) AS DESC_PERCENT,
COALESCE(fix.qty,0) AS DESC_FIXED,
COALESCE(SUM(ventas_productos.vp_cantidad*ventas_productos.vp_precio),0) AS Total_Value
FROM ventas
JOIN clientes ON clientes.id = ventas.cliente_id
JOIN users ON users.id = ventas.vendedor_id
LEFT OUTER JOIN canales_ventas ON canales_ventas.id = ventas.canal_venta_id
LEFT OUTER JOIN estados_venta ON estados_venta.id = ventas.estado_actual
LEFT OUTER JOIN metodos_pago ON metodos_pago.id = ventas.metodo_pago
LEFT OUTER JOIN canales_entrega ON canales_entrega.id = ventas.metodo_entrega
LEFT OUTER JOIN ventas_descuentos perc ON perc.orden_id = ventas.id AND perc.tipo = 1
LEFT OUTER JOIN ventas_descuentos fix ON fix.orden_id = ventas.id AND fix.tipo = 2
LEFT JOIN ventas_productos ON ventas_productos.vp_orden_id = ventas.id GROUP BY ventas.id
But I need that all the results match ventas.estado_actual = 7
I'd appreciate a lot the help. Thanks!
EDIT1:
I have tried Using WHERE in these ways:
After the last Join:
SELECT ventas.*,
clientes.nombre AS CLIENT_NOMBRE,
clientes.telefono AS TELEFONO,
users.nombre AS USERNAME,
canales_ventas.nombre AS CAN_VENTA,
estados_venta.nombre AS ESTADOS,
metodos_pago.nombre AS MET_PAGO,
canales_entrega.nombre AS CAN_ENTREGA,
canales_entrega.categoria AS CAN_ENTREGA_CAT,
COALESCE(perc.qty,0) AS DESC_PERCENT,
COALESCE(fix.qty,0) AS DESC_FIXED,
COALESCE(SUM(ventas_productos.vp_cantidad*ventas_productos.vp_precio),0) AS Total_Value
FROM ventas
JOIN clientes ON clientes.id = ventas.cliente_id
JOIN users ON users.id = ventas.vendedor_id
LEFT OUTER JOIN canales_ventas ON canales_ventas.id = ventas.canal_venta_id
LEFT OUTER JOIN estados_venta ON estados_venta.id = ventas.estado_actual
LEFT OUTER JOIN metodos_pago ON metodos_pago.id = ventas.metodo_pago
LEFT OUTER JOIN canales_entrega ON canales_entrega.id = ventas.metodo_entrega
LEFT OUTER JOIN ventas_descuentos perc ON perc.orden_id = ventas.id AND perc.tipo = 1
LEFT OUTER JOIN ventas_descuentos fix ON fix.orden_id = ventas.id AND fix.tipo = 2
LEFT JOIN ventas_productos ON ventas_productos.vp_orden_id = ventas.id GROUP BY ventas.id
WHERE ventas.estado_actual = 7
ERROR #1064 - Something is wrong in your syntax 'LIMIT 0, 25' on line 23
In the From Clause:
SELECT ventas.*,
clientes.nombre AS CLIENT_NOMBRE,
clientes.telefono AS TELEFONO,
users.nombre AS USERNAME,
canales_ventas.nombre AS CAN_VENTA,
estados_venta.nombre AS ESTADOS,
metodos_pago.nombre AS MET_PAGO,
canales_entrega.nombre AS CAN_ENTREGA,
canales_entrega.categoria AS CAN_ENTREGA_CAT,
COALESCE(perc.qty,0) AS DESC_PERCENT,
COALESCE(fix.qty,0) AS DESC_FIXED,
COALESCE(SUM(ventas_productos.vp_cantidad*ventas_productos.vp_precio),0) AS Total_Value
FROM ventas WHERE ventas.estado_actual = 7
JOIN clientes ON clientes.id = ventas.cliente_id
JOIN users ON users.id = ventas.vendedor_id
LEFT OUTER JOIN canales_ventas ON canales_ventas.id = ventas.canal_venta_id
LEFT OUTER JOIN estados_venta ON estados_venta.id = ventas.estado_actual
LEFT OUTER JOIN metodos_pago ON metodos_pago.id = ventas.metodo_pago
LEFT OUTER JOIN canales_entrega ON canales_entrega.id = ventas.metodo_entrega
LEFT OUTER JOIN ventas_descuentos perc ON perc.orden_id = ventas.id AND perc.tipo = 1
LEFT OUTER JOIN ventas_descuentos fix ON fix.orden_id = ventas.id AND fix.tipo = 2
LEFT JOIN ventas_productos ON ventas_productos.vp_orden_id = ventas.id GROUP BY ventas.id
ERROR - #1064 Again the same error
where clause must be before group by
WHERE ventas.estado_actual = 7 GROUP BY ventas.id
Sorry, I'm a newbee here and can't get everyhing right at one time in beautiful code lists. I'm in a prephase to (let) launch my database on a website, but before I do I need to create a (total) view with inner join. And i get a message of the infamous 1054 unknown column in 'on clause'. Here is the actual MySQL script. Can someone help me succeeding the script as a view ? Around this code in the script it stucks (between the stars in the FROM SYNTAX): INNER JOIN zorgaanbieder AS zorgaanbieder_1 ON (zorgverlener.Zorgaanbieder_ID = zorgaanbieder_1.Zorgaanbieder_ID). Please see code below
CREATE VIEW `fetch_data` AS
SELECT
zorgactiviteiten.ZA_code,
zorgactiviteiten.ZA_naam,
zorgactiviteiten.ZA_omschr_consument,
zorgprofielklasse.ZPK_oms,
behandelingen.Behandeling_criteria,
aanspraak.Aanspraak_omschr,
aanspraak.Aanspraak_machtiging,
cluster.Cluster_naam,
diagnosen.Diagnose_code,
diagnosen.Diagnose_naam,
diagnosen.Diagnose_groep,
diagnosen.Diagnose_hoofdstuk,
specialisme.Specialisme_naam,
zorgproducten.ZP_code,
zorgproducten.ZP_naam,
zorgproducten.ZP_omschr_consument,
zorgproductgroepen.ZPG_naam,
declaratie.Declaratie_code,
declaratie.Declaratie_zorg,
contractueel.Contractueel_uitleg,
contract.Contract_zorg,
contract.Contract_verzekerd,
contract.Contract_uitsluiting,
zorgverzekeraar.Zorgverzekeraar_verzekeraar,
zorgverzekeraar.Zorgverzekering_verzekering,
zorgverzekeraar.Zorgverzekering_soort,
zorgverzekeraar.Zorgverzekering_zorgkeuze,
concern.Concern_inkoop,
concern.Concern_label,
zorgverlener.Zorgverlener_plaats,
zorgverlener.Zorgverlener_regio,
zorgverlener.Zorgverlener_soort,
zorgaanbieder.Zorgaanbieder_informatie,
zorgaanbieder.Zorgaanbieder_website,
zorgaanbieder.Zorgaanbieder_reviews,
zorgaanbieder.Zorgaanbieder_rapport,
zorgaanbieder.Zorgaanbieder_oordeel,
zorgaanbieder.Zorgaanbieder_prijslijst,
prijslijst.Prijslijst_tarief,
prijslijst.Prijslijst_actie,
prijslijst.Prijslijst_soort,
prijslijst.Prijslijst_jaar
FROM
concern_zorgaanbieder_prijslijst
INNER JOIN
prijslijst ON (concern_zorgaanbieder_prijslijst.Prijslijst_ID = prijslijst.Prijslijst_ID)
INNER JOIN
concern ON (concern_zorgaanbieder_prijslijst.Concern_ID = concern.Concern_ID)
INNER JOIN
zorgaanbieder ON (concern_zorgaanbieder_prijslijst.Zorgaanbieder_ID = zorgaanbieder.Zorgaanbieder_ID)
INNER JOIN
zorgaanbieder AS zorgaanbieder_1 ON (zorgverlener.Zorgaanbieder_ID = zorgaanbieder_1.Zorgaanbieder_ID)
INNER JOIN
zorgverlener ON (contract.Zorgverlener_koppel = zorgverlener.Zorgverlener_ID)
INNER JOIN
concern AS concern_1 ON (zorgverzekeraar.Concern_ID = concern_1.Concern_ID)
INNER JOIN
zorgverzekeraar ON (contract.Zorgverzekeraar_koppel = zorgverzekeraar.Zorgverzekeraar_ID)
INNER JOIN
contract ON (contractueel_contract.Contract_ID = contract.Contract_ID)
INNER JOIN
contractueel_contract ON (contractueel.Contractueel_ID = contractueel_contract.Contract_ID)
INNER JOIN
contractueel ON (contractueel_decaratie.Contractueel_ID = contractueel.Contractueel_ID)
INNER JOIN
contractueel_decaratie ON (declaratie.Declaratie_code = contractueel_decaratie.Declaratie_code)
INNER JOIN
declaratie ON (zorgproducten_declaratie.Declaratie_code = declaratie.Declaratie_code)
INNER JOIN
zorgproducten_declaratie ON (zorgproducten.ZP_code = zorgproducten_declaratie.ZP_code)
INNER JOIN
zorgproductgroepen ON (zorgproducten.ZPG_code = zorgproductgroepen.ZPG_code)
INNER JOIN
zorgproducten ON (dbc.ZP_code = zorgproducten.ZP_code)
INNER JOIN
specialisme ON (diagnosen.Specialisme_code = specialisme.Specialisme_code)
INNER JOIN
diagnosen ON (diagnosebereik.Diagnose_ID = diagnosen.Diagnose_ID)
INNER JOIN
diagnosebereik ON (dbc_diagnosebereik.Diagnosebereik_naam = diagnosebereik.Diagnosebereik_naam)
INNER JOIN
dbc_diagnosebereik ON (diagnosebereik.Diagnosebereik_naam = dbc_diagnosebereik.Diagnosebereik_naam)
INNER JOIN
dbc ON (dbc_diagnosebereik.DBC_koppel = dbc.DBC_koppel)
INNER JOIN
behandelingen ON (dbc.DBC_koppel = behandelingen.DBC_koppel)
INNER JOIN
cluster ON (behandelingen.Cluster_ID = cluster.Cluster_ID)
INNER JOIN
aanspraak ON (behandelingen.Aanspraak_code = aanspraak.Aanspraak_code)
INNER JOIN
zorgactiviteit_behandelingen ON (behandelingen.Behandeling_naam = zorgactiviteit_behandelingen.Behandeling_naam)
INNER JOIN
zorgactiviteiten ON (zorgactiviteit_behandelingen.ZA_code = zorgactiviteiten.ZA_code)
INNER JOIN
zorgprofielklasse ON (zorgactiviteiten.ZPK_code = zorgprofielklasse.ZPK_code)
Debugging advice: Start small, test, then by grow by small increments and re-test.
I believe you problem is INCORRECT SEQUENCE of joins, NOT incorrect column references. e.g.
## this will fail
select a.* from a
join c on b.id = c.id ## c attempts to join to b = incorrect sequence of joins
join b on a.id = b.id
Below, table zorgverlener attempts to join to contract but it has not yet been joined.
SELECT
czp.*
FROM concern_zorgaanbieder_prijslijst as czp
...
INNER JOIN zorgverlener ON (contract.Zorgverlener_koppel = zorgverlener.Zorgverlener_ID)
...
INNER JOIN contract ON (contractueel_contract.Contract_ID = contract.Contract_ID)
Other tips:
Do use table aliases
Don't use unnecessary parentheses
To correct that issue change the order of the joins:
SELECT
czp.*
FROM concern_zorgaanbieder_prijslijst as czp
...
INNER JOIN contract AS C ON contractueel_contract.Contract_ID = contract.Contract_ID
...
INNER JOIN zorgverlener ON c.Zorgverlener_koppel = zorgverlener.Zorgverlener_ID
but now we see that contractueel_contract needs to go above contract and so on it goes.
I believe a more correct sequence of jois is as follows, but there are 2 joins I cannot solve:
SELECT
czp.*
FROM concern_zorgaanbieder_prijslijst AS czp
INNER JOIN prijslijst ON czp.Prijslijst_ID = prijslijst.Prijslijst_ID
INNER JOIN concern ON czp.Concern_ID = concern.Concern_ID
## problems in the next 2 lines, seem to be recursve
INNER JOIN diagnosebereik ON dbc_diagnosebereik.Diagnosebereik_naam = diagnosebereik.Diagnosebereik_naam
INNER JOIN dbc_diagnosebereik ON diagnosebereik.Diagnosebereik_naam = dbc_diagnosebereik.Diagnosebereik_naam
INNER JOIN dbc ON dbc_diagnosebereik.DBC_koppel = dbc.DBC_koppel
INNER JOIN zorgproducten ON dbc.ZP_code = zorgproducten.ZP_code
INNER JOIN zorgproducten_declaratie ON zorgproducten.ZP_code = zorgproducten_declaratie.ZP_code
INNER JOIN declaratie ON zorgproducten_declaratie.Declaratie_code = declaratie.Declaratie_code
INNER JOIN contractueel_decaratie ON declaratie.Declaratie_code = contractueel_decaratie.Declaratie_code
INNER JOIN contractueel ON contractueel_decaratie.Contractueel_ID = contractueel.Contractueel_ID
INNER JOIN contractueel_contract ON contractueel.Contractueel_ID = contractueel_contract.Contract_ID
INNER JOIN contract ON contractueel_contract.Contract_ID = contract.Contract_ID
INNER JOIN zorgverlener ON contract.Zorgverlener_koppel = zorgverlener.Zorgverlener_ID
INNER JOIN zorgaanbieder ON czp.Zorgaanbieder_ID = zorgaanbieder.Zorgaanbieder_ID
INNER JOIN zorgaanbieder AS zorgaanbieder_1 ON zorgverlener.Zorgaanbieder_ID = zorgaanbieder_1.Zorgaanbieder_ID
INNER JOIN zorgverzekeraar ON contract.Zorgverzekeraar_koppel = zorgverzekeraar.Zorgverzekeraar_ID
INNER JOIN concern AS concern_1 ON zorgverzekeraar.Concern_ID = concern_1.Concern_ID
INNER JOIN zorgproducten_declaratie ON zorgproducten.ZP_code = zorgproducten_declaratie.ZP_code
INNER JOIN zorgproductgroepen ON zorgproducten.ZPG_code = zorgproductgroepen.ZPG_code
INNER JOIN diagnosen ON diagnosebereik.Diagnose_ID = diagnosen.Diagnose_ID
INNER JOIN specialisme ON diagnosen.Specialisme_code = specialisme.Specialisme_code
INNER JOIN behandelingen ON dbc.DBC_koppel = behandelingen.DBC_koppel
INNER JOIN cluster ON behandelingen.Cluster_ID = cluster.Cluster_ID
INNER JOIN aanspraak ON behandelingen.Aanspraak_code = aanspraak.Aanspraak_code
INNER JOIN zorgactiviteit_behandelingen ON behandelingen.Behandeling_naam = zorgactiviteit_behandelingen.Behandeling_naam
INNER JOIN zorgactiviteiten ON zorgactiviteit_behandelingen.ZA_code = zorgactiviteiten.ZA_code
INNER JOIN zorgprofielklasse ON zorgactiviteiten.ZPK_code = zorgprofielklasse.ZPK_code
I have an SQL query like below which has a where clause as WHERE pg.active=1 AND tcg.active=1 AND tpg.active=1,issue right now is that one or all of pg.active tcg.active ,tpg.active is set to 1 at any time,in the case where one of these is not set to 1 query doesn't return anything.
How do I change the where clause to return if any of pg.active tcg.active ,tpg.active is set to 1?
SELECT
..........
FROM software_products_software_images spsi
INNER JOIN software_images si ON si.software_image_id = spsi.software_image_id
INNER JOIN software_products sp ON sp.id = spsi.software_product_id
LEFT JOIN software_products_software_images_testplan_gate tpg ON tpg.software_products_software_images_id = spsi.Id
LEFT JOIN test_suites tp ON tp.id = tpg.testplan_id
LEFT JOIN software_products_software_images_testcase_gate tcg ON tcg.software_products_software_images_id = spsi.Id
LEFT JOIN test_cases tc ON tc.id = tcg.testcase_id
LEFT JOIN test_suites ts ON ts.id = tc.test_suite_id
LEFT JOIN software_products_software_images_percentage_gate pg ON pg.software_products_software_images_id = spsi.Id
...........................
WHERE pg.active=1 AND tcg.active=1 AND tpg.active=1
AND si.software_image='NHSS.QSDK.7.0.1' ORDER BY si.software_image, ts.suite_name
I believe you need to encapsulate the OR part of the WHERE statement in round brackets so that it returns a TRUE on any OR match along with your other conditions.
SELECT
..........
FROM software_products_software_images spsi
INNER JOIN software_images si ON si.software_image_id = spsi.software_image_id
INNER JOIN software_products sp ON sp.id = spsi.software_product_id
LEFT JOIN software_products_software_images_testplan_gate tpg ON tpg.software_products_software_images_id = spsi.Id
LEFT JOIN test_suites tp ON tp.id = tpg.testplan_id
LEFT JOIN software_products_software_images_testcase_gate tcg ON tcg.software_products_software_images_id = spsi.Id
LEFT JOIN test_cases tc ON tc.id = tcg.testcase_id
LEFT JOIN test_suites ts ON ts.id = tc.test_suite_id
LEFT JOIN software_products_software_images_percentage_gate pg ON pg.software_products_software_images_id = spsi.Id
...........................
WHERE (pg.active=1 OR tcg.active=1 OR tpg.active=1)
AND si.software_image='NHSS.QSDK.7.0.1' ORDER BY si.software_image, ts.suite_name
SELECT jadwal_ajar.hari, jadwal_ajar.waktu, jenjang.nama_jenjang, jurusan.nama_jurusan, kelas.nama_kelas, mapel.nama_mapel, guru.nama_guru
FROM jadwal_ajar,guru , jenjang , jurusan , kelas , mapel
LEFT JOIN jadwal_ajar as a5 ON guru.kode_guru = a5.kode_guru
LEFT JOIN jadwal_ajar as a1 ON kelas.kode_kelas = a1.kode_kelas
LEFT JOIN jadwal_ajar as a2 ON mapel.kode_mapel = a2.kode_mapel
LEFT JOIN jadwal_ajar as a3 ON j.kode_jenjang = a3.kode_jenjang
LEFT JOIN jadwal_ajar as a4 ON jurusan.kode_jurusan = a4.kode_jurusan
The error you got is because of a missing field in the table guru, you should check it out.
And, from what I can see, I think that you are trying to join tables in the from, here is the way to achieve that:
SELECT jadwal_ajar.hari, jadwal_ajar.waktu,
jenjang.nama_jenjang, jurusan.nama_jurusan, kelas.nama_kelas,
mapel.nama_mapel, guru.nama_guru
FROM jadwal_ajar
LEFT JOIN guru ON guru.kode_guru = jadwal_ajar.kode_guru
LEFT JOIN kelas ON kelas.kode_kelas = jadwal_ajar.kode_kelas
LEFT JOIN mapel ON mapel.kode_mapel = jadwal_ajar.kode_mapel
LEFT JOIN jenjang ON jenjang.kode_jenjang = jadwal_ajar.kode_jenjang
LEFT JOIN jurusan ON jurusan.kode_jurusan = jadwal_ajar.kode_jurusan
I have the following query that works great when all of the INNER JOIN criteria is met. Unfortunately, this query returns zero results when for example INNER JOIN TableSample6 ON TableSample1.Field4 = TableSample6.Field6 is not found.
Can I restructure this query to return results even if some of the INNER JOIN values do not have a match in some cases?
SELECT DISTINCT
TableSample1.Field4,
TableSample.Field2,
TableSample2.Field2,
TableSample3.Field3,
TableSample4.Field4,
TableSample5.Field1,
TableSample.Field3,
TableSample6.Field1,
TableSample6.Field2,
TableSample7.Field7,
TableSample3.Field4,
TableSample4.Field2,
TableSample5.Field4
FROM TableSample1
INNER JOIN TableSample2 ON TableSample1.Field2 = TableSample2.Field4
INNER JOIN TableSample ON TableSample1.Field6 = TableSample.Field4
INNER JOIN TableSample3 ON TableSample1.Field3 = TableSample3.Field2
INNER JOIN TableSample4 ON TableSample1.Field7 = TableSample4.Field3
INNER JOIN TableSample5 ON TableSample1.Field8 = TableSample5.Field2
INNER JOIN TableSample6 ON TableSample1.Field4 = TableSample6.Field6
WHERE (((TableSample1.Field4)="xxxxxx" AND (TableSample.Field2)="xxxxxx"))
ORDER BY TableSample1.Field2;
You could use LEFT JOIN:
SELECT DISTINCT
t1.Field4,
t.Field2,
t2.Field2,
t3.Field3,
t4.Field4,
t5.Field1,
t.Field3,
t6.Field1,
t6.Field2,
t7.Field7, -- PROBLEM: you never join to TableSample7
t3.Field4,
t4.Field2,
t5.Field4
FROM TableSample1 t1
LEFT JOIN TableSample2 t2
ON t1.Field2 = t2.Field4
LEFT JOIN TableSample t
ON t1.Field6 = t.Field4
LEFT JOIN TableSample3 t3
ON t1.Field3 = t3.Field2
LEFT JOIN TableSample4 t4
ON t1.Field7 = t4.Field3
LEFT JOIN TableSample5 t5
ON t1.Field8 = t5.Field2
LEFT JOIN TableSample6 t6
ON t1.Field4 = t6.Field6
WHERE t1.Field4 = "xxxxxx" AND
t.Field2 = "xxxxxx"
ORDER BY t1.Field2;
You could also use COALESCE() to handle records which do not match to all of the tables. For example, if TableSample2.Field2 were varchar, you could use COALESCE(t2.Field2, 'NA') to show NA instead of NULL.