how to get all the data from database from 3 tables?












-1















My problem is, i am getting the datas which is present in all the 3 tables.But i want to display the data which is not present in any one of the table(that is empty space or 0 is printed on that item if it's not present in anyone of the table)..i googled and found that it can be done by fullouter join but i don't know how to use it..
Controller Code:



   public function St_statement(){

$startdate = $this->input->post('SDate');
$enddate = $this->input->post('EDate');
$date = str_replace('/', '-', $startdate);
$newDate = date("Y-m-d", strtotime($date));
$date2 = str_replace('/', '-', $enddate);
$newDate2 = date("Y-m-d", strtotime($date2));
$data['startdate'] = $startdate;
$data['enddate'] = $enddate;
if ($this->input->post('all'))
{
$this->db->where('billdate >=', $newDate);
$this->db->where('billdate <=', $newDate2);
$this->db->where('billdte >=', $newDate);
$this->db->where('billdte <=', $newDate2);
$this->db->select("Item");
$this->db->select("pgroup");
$this->db->select_sum("Stock");
$this->db->select_sum("quantity");
$this->db->select_sum("Qty");
$this->db->from('opstock');
$this->db->group_by("Item");
$this->db->order_by("pgroup",'asc');

$this->db->join('purchaseitem',' purchaseitem.Prdtname = opstock.Item','OUTER');
$this->db->join('salesitem','salesitem.Prdtname = purchaseitem.Prdtname','OUTER');
$this->db->join('itemmaster','itemmaster.itemname = purchaseitem.Prdtname','OUTER');
$this->db->join('pgroup','pgroup.pgroupid = itemmaster.catcode','OUTER');

$query = $this->db->get();
$data['query'] = $query;

$this->load->view('Inventory/St_Stmt', $data);
//$this->load->view('Inventory/St_Stmt1', $data);
}
if($this->input->post('selected'))
{
if($name = $this->input->post('businessType'))
{
$this->db->where('billdate >=', $newDate);
$this->db->where('billdate <=', $newDate2);
$this->db->where('billdte >=', $newDate);
$this->db->where('billdte <=', $newDate2);
$this->db->where('pgroup',$name);
$this->db->select("Item");
$this->db->select("pgroup");
$this->db->select_sum("Stock");
$this->db->select_sum("quantity");
$this->db->select_sum("Qty");
$this->db->from('opstock');
$this->db->group_by("Item");

$this->db->join('purchaseitem',' purchaseitem.Prdtname = opstock.Item','OUTER');
$this->db->join('salesitem','salesitem.Prdtname = purchaseitem.Prdtname','OUTER');
$this->db->join('itemmaster','itemmaster.itemname = purchaseitem.Prdtname','OUTER');
$this->db->join('pgroup','pgroup.pgroupid = itemmaster.catcode','OUTER');

$query = $this->db->get();
$data['query'] = $query;

$this->load->view('Inventory/St_Stmt', $data);


}

}
}









share|improve this question




















  • 1





    Hi. You are just asking us to write yet another presentation of outer join, plus a bespoke tutorial. That is too broad a question. And it is a faq because of all the other people who asked without researching or searching. Find a presentation & ask a specific question where you are stuck. Google your question. If you still need to ask then please read & act on Minimal, Complete, and Verifiable example. Also your text is not clear. Use enough words, sentences & references to parts of an example to clearly express what you want.

    – philipxy
    Nov 15 '18 at 12:34








  • 1





    Possible duplicate of How to do a FULL OUTER JOIN in MySQL?

    – philipxy
    Nov 15 '18 at 12:38
















-1















My problem is, i am getting the datas which is present in all the 3 tables.But i want to display the data which is not present in any one of the table(that is empty space or 0 is printed on that item if it's not present in anyone of the table)..i googled and found that it can be done by fullouter join but i don't know how to use it..
Controller Code:



   public function St_statement(){

$startdate = $this->input->post('SDate');
$enddate = $this->input->post('EDate');
$date = str_replace('/', '-', $startdate);
$newDate = date("Y-m-d", strtotime($date));
$date2 = str_replace('/', '-', $enddate);
$newDate2 = date("Y-m-d", strtotime($date2));
$data['startdate'] = $startdate;
$data['enddate'] = $enddate;
if ($this->input->post('all'))
{
$this->db->where('billdate >=', $newDate);
$this->db->where('billdate <=', $newDate2);
$this->db->where('billdte >=', $newDate);
$this->db->where('billdte <=', $newDate2);
$this->db->select("Item");
$this->db->select("pgroup");
$this->db->select_sum("Stock");
$this->db->select_sum("quantity");
$this->db->select_sum("Qty");
$this->db->from('opstock');
$this->db->group_by("Item");
$this->db->order_by("pgroup",'asc');

$this->db->join('purchaseitem',' purchaseitem.Prdtname = opstock.Item','OUTER');
$this->db->join('salesitem','salesitem.Prdtname = purchaseitem.Prdtname','OUTER');
$this->db->join('itemmaster','itemmaster.itemname = purchaseitem.Prdtname','OUTER');
$this->db->join('pgroup','pgroup.pgroupid = itemmaster.catcode','OUTER');

$query = $this->db->get();
$data['query'] = $query;

$this->load->view('Inventory/St_Stmt', $data);
//$this->load->view('Inventory/St_Stmt1', $data);
}
if($this->input->post('selected'))
{
if($name = $this->input->post('businessType'))
{
$this->db->where('billdate >=', $newDate);
$this->db->where('billdate <=', $newDate2);
$this->db->where('billdte >=', $newDate);
$this->db->where('billdte <=', $newDate2);
$this->db->where('pgroup',$name);
$this->db->select("Item");
$this->db->select("pgroup");
$this->db->select_sum("Stock");
$this->db->select_sum("quantity");
$this->db->select_sum("Qty");
$this->db->from('opstock');
$this->db->group_by("Item");

$this->db->join('purchaseitem',' purchaseitem.Prdtname = opstock.Item','OUTER');
$this->db->join('salesitem','salesitem.Prdtname = purchaseitem.Prdtname','OUTER');
$this->db->join('itemmaster','itemmaster.itemname = purchaseitem.Prdtname','OUTER');
$this->db->join('pgroup','pgroup.pgroupid = itemmaster.catcode','OUTER');

$query = $this->db->get();
$data['query'] = $query;

$this->load->view('Inventory/St_Stmt', $data);


}

}
}









share|improve this question




















  • 1





    Hi. You are just asking us to write yet another presentation of outer join, plus a bespoke tutorial. That is too broad a question. And it is a faq because of all the other people who asked without researching or searching. Find a presentation & ask a specific question where you are stuck. Google your question. If you still need to ask then please read & act on Minimal, Complete, and Verifiable example. Also your text is not clear. Use enough words, sentences & references to parts of an example to clearly express what you want.

    – philipxy
    Nov 15 '18 at 12:34








  • 1





    Possible duplicate of How to do a FULL OUTER JOIN in MySQL?

    – philipxy
    Nov 15 '18 at 12:38














-1












-1








-1








My problem is, i am getting the datas which is present in all the 3 tables.But i want to display the data which is not present in any one of the table(that is empty space or 0 is printed on that item if it's not present in anyone of the table)..i googled and found that it can be done by fullouter join but i don't know how to use it..
Controller Code:



   public function St_statement(){

$startdate = $this->input->post('SDate');
$enddate = $this->input->post('EDate');
$date = str_replace('/', '-', $startdate);
$newDate = date("Y-m-d", strtotime($date));
$date2 = str_replace('/', '-', $enddate);
$newDate2 = date("Y-m-d", strtotime($date2));
$data['startdate'] = $startdate;
$data['enddate'] = $enddate;
if ($this->input->post('all'))
{
$this->db->where('billdate >=', $newDate);
$this->db->where('billdate <=', $newDate2);
$this->db->where('billdte >=', $newDate);
$this->db->where('billdte <=', $newDate2);
$this->db->select("Item");
$this->db->select("pgroup");
$this->db->select_sum("Stock");
$this->db->select_sum("quantity");
$this->db->select_sum("Qty");
$this->db->from('opstock');
$this->db->group_by("Item");
$this->db->order_by("pgroup",'asc');

$this->db->join('purchaseitem',' purchaseitem.Prdtname = opstock.Item','OUTER');
$this->db->join('salesitem','salesitem.Prdtname = purchaseitem.Prdtname','OUTER');
$this->db->join('itemmaster','itemmaster.itemname = purchaseitem.Prdtname','OUTER');
$this->db->join('pgroup','pgroup.pgroupid = itemmaster.catcode','OUTER');

$query = $this->db->get();
$data['query'] = $query;

$this->load->view('Inventory/St_Stmt', $data);
//$this->load->view('Inventory/St_Stmt1', $data);
}
if($this->input->post('selected'))
{
if($name = $this->input->post('businessType'))
{
$this->db->where('billdate >=', $newDate);
$this->db->where('billdate <=', $newDate2);
$this->db->where('billdte >=', $newDate);
$this->db->where('billdte <=', $newDate2);
$this->db->where('pgroup',$name);
$this->db->select("Item");
$this->db->select("pgroup");
$this->db->select_sum("Stock");
$this->db->select_sum("quantity");
$this->db->select_sum("Qty");
$this->db->from('opstock');
$this->db->group_by("Item");

$this->db->join('purchaseitem',' purchaseitem.Prdtname = opstock.Item','OUTER');
$this->db->join('salesitem','salesitem.Prdtname = purchaseitem.Prdtname','OUTER');
$this->db->join('itemmaster','itemmaster.itemname = purchaseitem.Prdtname','OUTER');
$this->db->join('pgroup','pgroup.pgroupid = itemmaster.catcode','OUTER');

$query = $this->db->get();
$data['query'] = $query;

$this->load->view('Inventory/St_Stmt', $data);


}

}
}









share|improve this question
















My problem is, i am getting the datas which is present in all the 3 tables.But i want to display the data which is not present in any one of the table(that is empty space or 0 is printed on that item if it's not present in anyone of the table)..i googled and found that it can be done by fullouter join but i don't know how to use it..
Controller Code:



   public function St_statement(){

$startdate = $this->input->post('SDate');
$enddate = $this->input->post('EDate');
$date = str_replace('/', '-', $startdate);
$newDate = date("Y-m-d", strtotime($date));
$date2 = str_replace('/', '-', $enddate);
$newDate2 = date("Y-m-d", strtotime($date2));
$data['startdate'] = $startdate;
$data['enddate'] = $enddate;
if ($this->input->post('all'))
{
$this->db->where('billdate >=', $newDate);
$this->db->where('billdate <=', $newDate2);
$this->db->where('billdte >=', $newDate);
$this->db->where('billdte <=', $newDate2);
$this->db->select("Item");
$this->db->select("pgroup");
$this->db->select_sum("Stock");
$this->db->select_sum("quantity");
$this->db->select_sum("Qty");
$this->db->from('opstock');
$this->db->group_by("Item");
$this->db->order_by("pgroup",'asc');

$this->db->join('purchaseitem',' purchaseitem.Prdtname = opstock.Item','OUTER');
$this->db->join('salesitem','salesitem.Prdtname = purchaseitem.Prdtname','OUTER');
$this->db->join('itemmaster','itemmaster.itemname = purchaseitem.Prdtname','OUTER');
$this->db->join('pgroup','pgroup.pgroupid = itemmaster.catcode','OUTER');

$query = $this->db->get();
$data['query'] = $query;

$this->load->view('Inventory/St_Stmt', $data);
//$this->load->view('Inventory/St_Stmt1', $data);
}
if($this->input->post('selected'))
{
if($name = $this->input->post('businessType'))
{
$this->db->where('billdate >=', $newDate);
$this->db->where('billdate <=', $newDate2);
$this->db->where('billdte >=', $newDate);
$this->db->where('billdte <=', $newDate2);
$this->db->where('pgroup',$name);
$this->db->select("Item");
$this->db->select("pgroup");
$this->db->select_sum("Stock");
$this->db->select_sum("quantity");
$this->db->select_sum("Qty");
$this->db->from('opstock');
$this->db->group_by("Item");

$this->db->join('purchaseitem',' purchaseitem.Prdtname = opstock.Item','OUTER');
$this->db->join('salesitem','salesitem.Prdtname = purchaseitem.Prdtname','OUTER');
$this->db->join('itemmaster','itemmaster.itemname = purchaseitem.Prdtname','OUTER');
$this->db->join('pgroup','pgroup.pgroupid = itemmaster.catcode','OUTER');

$query = $this->db->get();
$data['query'] = $query;

$this->load->view('Inventory/St_Stmt', $data);


}

}
}






php mysql codeigniter full-outer-join






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 12:45









philipxy

11.7k42253




11.7k42253










asked Nov 15 '18 at 12:14









TeddyTeddy

6110




6110








  • 1





    Hi. You are just asking us to write yet another presentation of outer join, plus a bespoke tutorial. That is too broad a question. And it is a faq because of all the other people who asked without researching or searching. Find a presentation & ask a specific question where you are stuck. Google your question. If you still need to ask then please read & act on Minimal, Complete, and Verifiable example. Also your text is not clear. Use enough words, sentences & references to parts of an example to clearly express what you want.

    – philipxy
    Nov 15 '18 at 12:34








  • 1





    Possible duplicate of How to do a FULL OUTER JOIN in MySQL?

    – philipxy
    Nov 15 '18 at 12:38














  • 1





    Hi. You are just asking us to write yet another presentation of outer join, plus a bespoke tutorial. That is too broad a question. And it is a faq because of all the other people who asked without researching or searching. Find a presentation & ask a specific question where you are stuck. Google your question. If you still need to ask then please read & act on Minimal, Complete, and Verifiable example. Also your text is not clear. Use enough words, sentences & references to parts of an example to clearly express what you want.

    – philipxy
    Nov 15 '18 at 12:34








  • 1





    Possible duplicate of How to do a FULL OUTER JOIN in MySQL?

    – philipxy
    Nov 15 '18 at 12:38








1




1





Hi. You are just asking us to write yet another presentation of outer join, plus a bespoke tutorial. That is too broad a question. And it is a faq because of all the other people who asked without researching or searching. Find a presentation & ask a specific question where you are stuck. Google your question. If you still need to ask then please read & act on Minimal, Complete, and Verifiable example. Also your text is not clear. Use enough words, sentences & references to parts of an example to clearly express what you want.

– philipxy
Nov 15 '18 at 12:34







Hi. You are just asking us to write yet another presentation of outer join, plus a bespoke tutorial. That is too broad a question. And it is a faq because of all the other people who asked without researching or searching. Find a presentation & ask a specific question where you are stuck. Google your question. If you still need to ask then please read & act on Minimal, Complete, and Verifiable example. Also your text is not clear. Use enough words, sentences & references to parts of an example to clearly express what you want.

– philipxy
Nov 15 '18 at 12:34






1




1





Possible duplicate of How to do a FULL OUTER JOIN in MySQL?

– philipxy
Nov 15 '18 at 12:38





Possible duplicate of How to do a FULL OUTER JOIN in MySQL?

– philipxy
Nov 15 '18 at 12:38












1 Answer
1






active

oldest

votes


















1














$query = "SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
LEFT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
LEFT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
LEFT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC
UNION
SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
RIGHT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
LEFT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
LEFT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC
SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
LEFT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
RIGHT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
LEFT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC
UNION
SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
LEFT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
LEFT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
RIGHT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC";



$query = $this->db->query($query);






share|improve this answer


























  • Please look at the edited version of your post before you post. Please click on 'edit' & read the edit help & format properly. Please read How to Ask & How to Answer--this question is too broad & unclear & a faq duplicate & shouldn't be answered. And when answering please don't just dump code. PS There is no full outer join in MySQL.

    – philipxy
    Nov 15 '18 at 12:32













  • it shows an error

    – Teddy
    Nov 15 '18 at 12:38













  • Error Number: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'OUTER JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item FULL OUTER JOIN ' at line 1

    – Teddy
    Nov 15 '18 at 12:39











  • SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock FULL OUTER JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item FULL OUTER JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname FULL OUTER JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname FULL OUTER JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '1' AND billdate <= '1' AND billdte >= '2018-11-15' AND billdte <= '2018-11-15' GROUP BY Item ORDER BY pgroup ASC Filename: D:/xampp/htdocs/Yuva/system/database/DB_driver.php Line Number: 691

    – Teddy
    Nov 15 '18 at 12:39











  • @esakkichandra MySQL does not have full outer join syntax. See my comments on this answer & the question.

    – philipxy
    Nov 15 '18 at 12:48











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319290%2fhow-to-get-all-the-data-from-database-from-3-tables%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














$query = "SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
LEFT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
LEFT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
LEFT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC
UNION
SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
RIGHT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
LEFT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
LEFT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC
SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
LEFT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
RIGHT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
LEFT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC
UNION
SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
LEFT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
LEFT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
RIGHT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC";



$query = $this->db->query($query);






share|improve this answer


























  • Please look at the edited version of your post before you post. Please click on 'edit' & read the edit help & format properly. Please read How to Ask & How to Answer--this question is too broad & unclear & a faq duplicate & shouldn't be answered. And when answering please don't just dump code. PS There is no full outer join in MySQL.

    – philipxy
    Nov 15 '18 at 12:32













  • it shows an error

    – Teddy
    Nov 15 '18 at 12:38













  • Error Number: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'OUTER JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item FULL OUTER JOIN ' at line 1

    – Teddy
    Nov 15 '18 at 12:39











  • SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock FULL OUTER JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item FULL OUTER JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname FULL OUTER JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname FULL OUTER JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '1' AND billdate <= '1' AND billdte >= '2018-11-15' AND billdte <= '2018-11-15' GROUP BY Item ORDER BY pgroup ASC Filename: D:/xampp/htdocs/Yuva/system/database/DB_driver.php Line Number: 691

    – Teddy
    Nov 15 '18 at 12:39











  • @esakkichandra MySQL does not have full outer join syntax. See my comments on this answer & the question.

    – philipxy
    Nov 15 '18 at 12:48
















1














$query = "SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
LEFT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
LEFT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
LEFT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC
UNION
SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
RIGHT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
LEFT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
LEFT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC
SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
LEFT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
RIGHT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
LEFT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC
UNION
SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
LEFT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
LEFT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
RIGHT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC";



$query = $this->db->query($query);






share|improve this answer


























  • Please look at the edited version of your post before you post. Please click on 'edit' & read the edit help & format properly. Please read How to Ask & How to Answer--this question is too broad & unclear & a faq duplicate & shouldn't be answered. And when answering please don't just dump code. PS There is no full outer join in MySQL.

    – philipxy
    Nov 15 '18 at 12:32













  • it shows an error

    – Teddy
    Nov 15 '18 at 12:38













  • Error Number: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'OUTER JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item FULL OUTER JOIN ' at line 1

    – Teddy
    Nov 15 '18 at 12:39











  • SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock FULL OUTER JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item FULL OUTER JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname FULL OUTER JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname FULL OUTER JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '1' AND billdate <= '1' AND billdte >= '2018-11-15' AND billdte <= '2018-11-15' GROUP BY Item ORDER BY pgroup ASC Filename: D:/xampp/htdocs/Yuva/system/database/DB_driver.php Line Number: 691

    – Teddy
    Nov 15 '18 at 12:39











  • @esakkichandra MySQL does not have full outer join syntax. See my comments on this answer & the question.

    – philipxy
    Nov 15 '18 at 12:48














1












1








1







$query = "SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
LEFT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
LEFT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
LEFT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC
UNION
SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
RIGHT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
LEFT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
LEFT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC
SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
LEFT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
RIGHT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
LEFT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC
UNION
SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
LEFT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
LEFT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
RIGHT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC";



$query = $this->db->query($query);






share|improve this answer















$query = "SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
LEFT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
LEFT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
LEFT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC
UNION
SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
RIGHT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
LEFT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
LEFT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC
SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
LEFT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
RIGHT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
LEFT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC
UNION
SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock
LEFT JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item
LEFT JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname
RIGHT JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname
LEFT JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '".$newDate."' AND billdate <= '".$newDate2."' AND billdte >= '".$newDate."' AND billdte <= '".$newDate2."' GROUP BY Item ORDER BY pgroup ASC";



$query = $this->db->query($query);







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 15 '18 at 13:06

























answered Nov 15 '18 at 12:30









Mac RathodMac Rathod

215




215













  • Please look at the edited version of your post before you post. Please click on 'edit' & read the edit help & format properly. Please read How to Ask & How to Answer--this question is too broad & unclear & a faq duplicate & shouldn't be answered. And when answering please don't just dump code. PS There is no full outer join in MySQL.

    – philipxy
    Nov 15 '18 at 12:32













  • it shows an error

    – Teddy
    Nov 15 '18 at 12:38













  • Error Number: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'OUTER JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item FULL OUTER JOIN ' at line 1

    – Teddy
    Nov 15 '18 at 12:39











  • SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock FULL OUTER JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item FULL OUTER JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname FULL OUTER JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname FULL OUTER JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '1' AND billdate <= '1' AND billdte >= '2018-11-15' AND billdte <= '2018-11-15' GROUP BY Item ORDER BY pgroup ASC Filename: D:/xampp/htdocs/Yuva/system/database/DB_driver.php Line Number: 691

    – Teddy
    Nov 15 '18 at 12:39











  • @esakkichandra MySQL does not have full outer join syntax. See my comments on this answer & the question.

    – philipxy
    Nov 15 '18 at 12:48



















  • Please look at the edited version of your post before you post. Please click on 'edit' & read the edit help & format properly. Please read How to Ask & How to Answer--this question is too broad & unclear & a faq duplicate & shouldn't be answered. And when answering please don't just dump code. PS There is no full outer join in MySQL.

    – philipxy
    Nov 15 '18 at 12:32













  • it shows an error

    – Teddy
    Nov 15 '18 at 12:38













  • Error Number: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'OUTER JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item FULL OUTER JOIN ' at line 1

    – Teddy
    Nov 15 '18 at 12:39











  • SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock FULL OUTER JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item FULL OUTER JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname FULL OUTER JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname FULL OUTER JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '1' AND billdate <= '1' AND billdte >= '2018-11-15' AND billdte <= '2018-11-15' GROUP BY Item ORDER BY pgroup ASC Filename: D:/xampp/htdocs/Yuva/system/database/DB_driver.php Line Number: 691

    – Teddy
    Nov 15 '18 at 12:39











  • @esakkichandra MySQL does not have full outer join syntax. See my comments on this answer & the question.

    – philipxy
    Nov 15 '18 at 12:48

















Please look at the edited version of your post before you post. Please click on 'edit' & read the edit help & format properly. Please read How to Ask & How to Answer--this question is too broad & unclear & a faq duplicate & shouldn't be answered. And when answering please don't just dump code. PS There is no full outer join in MySQL.

– philipxy
Nov 15 '18 at 12:32







Please look at the edited version of your post before you post. Please click on 'edit' & read the edit help & format properly. Please read How to Ask & How to Answer--this question is too broad & unclear & a faq duplicate & shouldn't be answered. And when answering please don't just dump code. PS There is no full outer join in MySQL.

– philipxy
Nov 15 '18 at 12:32















it shows an error

– Teddy
Nov 15 '18 at 12:38







it shows an error

– Teddy
Nov 15 '18 at 12:38















Error Number: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'OUTER JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item FULL OUTER JOIN ' at line 1

– Teddy
Nov 15 '18 at 12:39





Error Number: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'OUTER JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item FULL OUTER JOIN ' at line 1

– Teddy
Nov 15 '18 at 12:39













SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock FULL OUTER JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item FULL OUTER JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname FULL OUTER JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname FULL OUTER JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '1' AND billdate <= '1' AND billdte >= '2018-11-15' AND billdte <= '2018-11-15' GROUP BY Item ORDER BY pgroup ASC Filename: D:/xampp/htdocs/Yuva/system/database/DB_driver.php Line Number: 691

– Teddy
Nov 15 '18 at 12:39





SELECT Item, pgroup, SUM(Stock) AS Stock, SUM(quantity) AS quantity, SUM(Qty) AS Qty FROM opstock FULL OUTER JOIN purchaseitem ON purchaseitem.Prdtname = opstock.Item FULL OUTER JOIN salesitem ON salesitem.Prdtname = purchaseitem.Prdtname FULL OUTER JOIN itemmaster ON itemmaster.itemname = purchaseitem.Prdtname FULL OUTER JOIN pgroup ON pgroup.pgroupid = itemmaster.catcode WHERE billdate >= '1' AND billdate <= '1' AND billdte >= '2018-11-15' AND billdte <= '2018-11-15' GROUP BY Item ORDER BY pgroup ASC Filename: D:/xampp/htdocs/Yuva/system/database/DB_driver.php Line Number: 691

– Teddy
Nov 15 '18 at 12:39













@esakkichandra MySQL does not have full outer join syntax. See my comments on this answer & the question.

– philipxy
Nov 15 '18 at 12:48





@esakkichandra MySQL does not have full outer join syntax. See my comments on this answer & the question.

– philipxy
Nov 15 '18 at 12:48




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319290%2fhow-to-get-all-the-data-from-database-from-3-tables%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

The Sandy Post

Danny Elfman

Pages that link to "Head v. Amoskeag Manufacturing Co."