Welcome Guest, Not a member yet? Register   Sign In
Merging/Join data from two sql tables
#1

[eluser]m4ikel[/eluser]
Hello all,

I'm having a issue creating a complex join and I'm unsure if this is even possible but I thought I give it a shot here. (Its hard to explain though so forgive me)

I have two tables:

Code:
MySQL TABLES

default_views
-------------
- dvid = autoincrement id
- vna = view name
- tpl
- pro
- typ

custom_views
-------------
- cvid = same as dvid
- sid = SiteID
- typ
- vna = view name
- tpl

What I want to do is join both tables but ONLY if 'sid' is the same as the siteID specified by the cms.

At this moment Im trying to use:

Code:
$sid = 2;

$this->db->select('
default_views.dvid,
default_views.vna,
default_views.tpl,
default_views.typ,
default_views.pro,
custom_views.sid
');
$this->db->from('default_views');
$this->db->join('custom_views', 'default_views.dvid = custom_views.cvid', 'left');
$this->db->where('custom_views.sid',$sid);
$q = $this->db->get();

Which works fine, but it just returns custom_views which match the SiteID. I want it to return default_views at all time and add custom_views 'sid' to the row of the default_views only when sideid matches.

Anyone has any suggestion on how to proceed on this? Reason is, I dont want to use any dirty mysql loops for returing the data.

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB