我正在CI中开发一个应用程序,这是我的查询回显,它没有返回任何输出
SELECT `institute`.`name`
, `user`.`username`
, `ambassador`.`recommended_by`
, `ambassador`.`degree_level`
, `ambassador`.`about`
, `ambassador`.`is_active`
, `ambassador`.`added_on`
FROM `user`
INNER JOIN `ambassador` ON `ambassador`.`user_id` = `user`.`id`
AND `ambassador`.`recommended_by` = `user`.`id`
INNER JOIN `institute` ON `ambassador`.`institute_id` = `institute`.`id
解释
表名
真实测验:
我能够获得发送到Ambassador表的数据作为ID,因为表的结构是这样构建的。但在视图部分我不想显示那些ID,即
我非常希望能从这里得到一些帮助。
更新
大使表:
id
user_id
institute_id
degree_level
recommended_by
about
added_on
is_active
用户表:
id
first_name
last_name
username
email
password
gender
cnic
user_type
学院表
id
name
city_id
group_name
再次更新
目前,以下查询对我有用,但我正在寻找一些有效的解决方案。
$this->db->select(
'institute.name,
user.username,
ambassador.id,
ambassador.degree_level,
ambassador.about,ambassador.is_active,ambassador.added_on');
$this->db->from('user');
$this->db->join('ambassador', 'ambassador.user_id = user.id', 'INNER');
$this->db->join('institute', 'ambassador.institute_id = institute.id', 'INNER');
$query['q1'] = $this->db->get();
$this->db->select('
user.username');
第二次查询
$this->db->from('user');
$this->db->join('ambassador', 'ambassador.recommended_by=user.id', 'INNER');
$query['q2'] = $this->db->get();
**另一个尝试:** 现在尝试子查询,不确定这是否正确。在纠正这一点时,我们将不胜感激。
SELECT
(
SELECT
`a`.id,
`i`.`name`,
`u`.`username`,
`a`.`degree_level`,
`a`.`recommended_by`,
`a`.`about`,
`a`.`is_active`,
`a`.added_on
),
(
SELECT
`u`.`username`
FROM
`user`
WHERE
`user_type` = "admin"
)
FROM
`user` AS `u`
LEFT OUTER JOIN `institute` AS `i`
ON
`a`.`institute_id` = `i`.`id`
LEFT OUTER JOIN `ambassador` AS `a`
ON
`a`.`user_id` = `u`.`id`
LEFT OUTER JOIN `admin` AS `ad`
ON
`a`.`recommended_by` = `ad`.`user_id` LIMIT 0, 25
MySQL said: Documentation
#1241 - Operand should contain 1 column(s)