你们可以帮我解决这个问题吗?

错误显示为“ on子句中的未知列'd.idspesialis”'

SELECT a.*, b.*, c.*,  e.*,d.*, f.*,g.*
FROM ckehamilan a
    INNER JOIN  pasien  b
            ON a.noRM=b.noRM
    INNER JOIN ( select idPegawai , NamaPegawai as NamaDokter from tpegawai )  d
            ON a.idPegawai=d.idPegawai
     LEFT JOIN spesialis e
            ON e.idspesialis=d.idspesialis
    INNER JOIN ( select idPegawai , NamaPegawai as NamaParamedis from  tpegawai )  f
            ON a.idparamedis=f.idPegawai
     LEFT JOIN imunisasi g
            ON a.idimunisasi=g.idimunisasi
    INNER JOIN  ruang  c
            ON a.idruang=c.idruang

最佳答案

您的子查询没有列idspesialis

尝试这个,

(
    SELECT idPegawai, NamaPegawai AS NamaDokter, idspesialis
    FROM tpegawai
) d


您的完整查询应如下所示,

SELECT a.*
    , b.*
    , c.*
    , e.*
    , d.*
    , f.*
    , g.*
FROM ckehamilan a
    INNER JOIN pasien b
        ON a.noRM = b.noRM
    INNER JOIN
        (
            SELECT idPegawai, NamaPegawai AS NamaDokter, idspesialis
            FROM tpegawai
        ) d
        ON a.idPegawai = d.idPegawai
    LEFT JOIN spesialis e
        ON e.idspesialis = d.idspesialis
    INNER JOIN
        (
            SELECT idPegawai , NamaPegawai AS NamaParamedis
            FROM tpegawai
        ) f
        ON a.idparamedis = f.idPegawai
    LEFT JOIN imunisasi g
        ON a.idimunisasi = g.idimunisasi
    INNER JOIN ruang c
        ON a.idruang = c.idruang

关于mysql - JOIN许多表中的未知列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13758376/

10-09 04:35