多个表的多个列连接到同一表

时间:2018-07-11 17:18:08

标签: php mysql codeigniter join inner-join

我有一个查询。

我在mysql数据库中有3个表。

我想用这些规则连接我的表,多个表的多个列连接到同一表的一列。

MySQL示例如下。预先感谢。

SELECT
    s.*,e.* 
    , m1.m_id AS 'mid'
    , m1.m_name AS 'mname' 
    , m2.m_id AS 'bid'
    , m2.m_name AS 'bname'
    , e1.e_id AS 'tid'
    , e1.e_name AS 'tname'
    , e2.e_id AS 'topid'
    , e2.e_name AS 'topname'
    FROM s s,e e
    INNER JOIN m m1
    ON s.s_m_id = m1.m_id
    INNER JOIN m m2
    ON s.s_b_id = m2.m_id
    INNER JOIN e e1
    ON s.s_t_id = e1.e_id
    INNER JOIN e e2
    ON s.s_t_t_id = e2.e_id
    WHERE s_id =1

2 个答案:

答案 0 :(得分:0)

$this->db->select("s.*,e.* 
    , m1.m_id AS 'mid'
    , m1.m_name AS 'mname' 
    , m2.m_id AS 'bid'
    , m2.m_name AS 'bname'
    , e1.e_id AS 'tid'
    , e1.e_name AS 'tname'
    , e2.e_id AS 'topid'
    , e2.e_name AS 'topname'");
$this->db->from("FROM s");
$this->db->join("m m1
     s.s_m_id = m1.m_id","inner");
$this->db->join("m m2
     s.s_b_id = m2.m_id","inner");
$this->db->join("e e1
    s.s_t_id = e1.e_id","inner");
$this->db->join(" e e2
    s.s_t_t_id = e2.e_id","inner");
$this->db->where('s_id','1');
$this->db->get();

答案 1 :(得分:0)

您的代码不起作用吗?尝试删除

上的“ FROM”
self.progressView.setProgress(0, animated: false)
    self.progressLabel.text = "0.0 %"
    self.finalUrlLabel.text = ""

    let request = URLRequest.init(url: URL.init(string: "http://techslides.com/demos/samples/sample.mp4")!)

    let downloadKey = SDDownloadManager.shared.dowloadFile(withRequest: request,
                                                           inDirectory: directoryName,
                                                           withName: nil,
                                                           onProgress:  { [weak self] (progress) in
                                                            let percentage = String(format: "%.1f %", (progress * 100))
                                                            self?.progressView.setProgress(Float(progress), animated: true)
                                                            self?.progressLabel.text = "\(percentage) %"
                                                            print("percentage",percentage)
    }) { [weak self] (error, url) in
        if let error = error {
            print("Error is \(error as NSError)")
        } else {
            if let url = url {
                print("Downloaded file's url is \(url.path)")
                self?.finalUrlLabel.text = url.path
            }
        }
    }

    print("The key is \(downloadKey!)")

    let dasd = SDDownloadManager.shared.ongoingDownloads
    print("dasd",dasd.count)