[英]How to use select query with two tables using mysql codeigniter
I have two tables users
and employers
in mysql, I just want to get all records from both tables at same time. 我在mysql中有两个表
users
和employers
,我只想同时从两个表中获取所有记录。
How can I do this using codeigniter ? 我怎么能用codeigniter做到这一点?
According to your comment, you don't have relation between both tables, so you can get the data as like this cross join: 根据您的评论,您没有两个表之间的关系,因此您可以像这个交叉连接一样获取数据:
$this->db->select('users.*,employers.*');
$this->db->from('users,employers');
$query = $this->db->get();
return $query->result();
If you want to use LIKE
clause then you can just add: 如果你想使用
LIKE
子句,那么你可以添加:
$this->db->like('users.entity', $search_keyword_here, "both"); // here both means '%your keyword%'
$this->db->or_like('users.skills', $search_keyword_here, "both"); // here both means '%your keyword%'
You can use or_like for employers table also. 你也可以使用or_like for employer表。
Note that, when we use cross join it will produce result like (users no of rows *employers no of rows)
请注意,当我们使用交叉连接时,它将产生结果
(users no of rows *employers no of rows)
Try this sql query
试试这个SQL查询
SELECT table1.column1, table2.column2....(put all tables and columns name that you want to join)
FROM table1
FULL JOIN table2
ON table1.common_field = table2.common_field;
[or go to this site]
[或者去这个网站]
https://www.tutorialspoint.com/sql/sql-full-joins.htm
https://www.tutorialspoint.com/sql/sql-full-joins.htm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.