0

I will explain my condition first So i have 2 tables, one is table tb_form, second is tb_pendaftaran

tb_form         tb_pendaftaran
id_form         id_pendaftaran
judul           id_form
value           value

then i want to show all judul from tb_form, and get the value from tb_pendaftaran.

In case 1 : tb_form have 5 id_form, and all the id_form is in tb_pendaftaran too. it works fine, all the record showed up

In case 2 : but the problem now is that when tb_form have 5 id_form, and tb_pendaftaran only have 3 of the ids, the result only show 3 records not five. I wanted to show all the five judul based on table one, and if it doesnt have value from tb_pendaftaran, then the value should show nothing

*sorry for my poor english

Thankyou, and help is apreciated

Raven Choi
  • 73
  • 1
  • 9
  • Without seeing your code it's impossible to give an exact answer, but basically you need to `LEFT JOIN` the two tables instead of `INNER JOIN` – Nick Apr 03 '18 at 04:33
  • https://stackoverflow.com/questions/14366004/sql-server-join-missing-null-values – Stacking For Heap Apr 03 '18 at 04:33

2 Answers2

0

There is a nice graph for sql joins. Just look at the bottom of the page.

In your case you should use the following sql phrase:

select f.*, p.id_pendaftaran, p.value from tb_form f 
left join tb_pendaftaran p on f.id_form = p.id_form 

So, you will list all of the rows on first table and if there are any matches on table tb_pendaftaran the related columns will be filled up.

enter image description here

kylngr
  • 61
  • 8
0

Hi Raven Please try the below code once.

$CI->db->from('tb_form'); $CI->db->join('tb_pendaftaran', 'tb_pendaftaran.id_form = tb_form.id_form', 'left');

Thanks, Lavish Tyagi

Lavish Tyagi
  • 223
  • 5
  • 10