本文介绍了从一个表中获取所有列的值,并从第二个表中获取另一列的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从数据库中获取结果.

I need to get result from my database.

我有两个表"travels"和"airlines",我想从travels表中获取所有列的结果,即("id","name","airline_name","price","via")并从第二个表开始,该表是基于列("id","name","logo")的航空公司.

I have two table "travels" and "airlines" and I want to get result of all the columns from travels table which is ("id","name","airline_name","price","via") and from second table which is airlines based on the columns("id","name","logo").

我想获得与旅行表中的航空公司名称相同的徽标".

I want to get "logo" whose name is the same as airline_name in the travel table.

我该怎么办?我应该使用join吗?到目前为止,我的查询是:

What should I do? Should I used join?? So far my query is:

 $this->db->select();
 $this->db->from('travels');
 $this->db->join('airlines', 'travels.airline_name = airlines.name','inner');
 $this->db->group_by('travels.destination'); 

我正在使用CodeIgniter.

I am using CodeIgniter.

推荐答案

SELECT
  t.id,
  t.name,
  t.airline_name,
  t.price,
  t.via,
  a.logo
FROM travels AS t
  INNER JOIN airlines AS a ON (t.airline_name = a.logo);

这篇关于从一个表中获取所有列的值,并从第二个表中获取另一列的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 15:07