Welcome Guest, Not a member yet? Register   Sign In
How to write this SQL statement in Active Record
#6

[eluser]WanWizard[/eluser]
All fine, but your query has 'user_id' in the WHERE clause. And your query refers to a user_id field in the users table, and an id field in the example_tbl table. So what is it?

It's very difficult answering questions if the question isn't correct, don't you think?

In the assumption that there are no more suprises, and the field is called user_id, the query should be
Code:
$this->db->query('SELECT a.slogan, a.brief, u.user_id, u.name FROM example_tbl AS a JOIN users AS u USING (user_id) WHERE u.user_id = "' . USER_ID . '"');
or
Code:
$this->db->select('a.slogan, a.brief, u.user_id, u.name');
$this->db->from('example_tbl a');
$this->db->join('users u', 'a.user_id = u.user_id'); // standard AR doesn't support USING
$this->db->where('u.user_id="'.USER_ID.'"');
$query = $this->db->get();


Messages In This Thread
How to write this SQL statement in Active Record - by El Forum - 06-10-2010, 08:11 AM
How to write this SQL statement in Active Record - by El Forum - 06-10-2010, 08:36 AM
How to write this SQL statement in Active Record - by El Forum - 06-10-2010, 09:10 AM
How to write this SQL statement in Active Record - by El Forum - 06-10-2010, 09:25 AM
How to write this SQL statement in Active Record - by El Forum - 06-10-2010, 10:27 AM
How to write this SQL statement in Active Record - by El Forum - 06-10-2010, 11:03 AM
How to write this SQL statement in Active Record - by El Forum - 06-14-2010, 12:12 PM
How to write this SQL statement in Active Record - by El Forum - 06-14-2010, 05:36 PM
How to write this SQL statement in Active Record - by El Forum - 06-14-2010, 10:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB