June 16, 2014 at 11:34 pm
Iam having these tables
category
cat_id (int)
name(varchar)
sub_category
sub_cat_id(int)
name(varchar)
category-subcategory-association
cat_sub_cat_id(int)
cat_id(int)
sub_cat_id(int)
order_master
order_id(int)
cat_sub_cat_id(int)
cat_id(int)
sub_id(int)
order_name(varchar)
These are my tables
while inserting the data into database if i give cat_id,sub_cat_id it should check first whether this ids are present in the association table or not if the ids are there in the association table then we should get that association id and should insert into the database table of order_master how can i do this can anyone help me.
Thanks in advance
June 17, 2014 at 1:17 am
You can add the EXISTS statement to the WHERE clause of the INSERT statement.
A mock-up:
INSERT INTO order_master
SELECT values
FROM somewhere
WHERE EXISTS (SELECT 1 FROM category-subcategory-association WHERE cat_id = myCatID and sub_cat_id = mySubCatID);
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
June 17, 2014 at 1:27 am
what is mycatId which u have i didnt get that
June 17, 2014 at 1:32 am
ashalatha.cse76 (6/17/2014)
what is mycatId which u have i didnt get that
It's just a placeholder I made up.
You have to substitute it with your own values/columns/variables...
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
June 17, 2014 at 1:44 am
in where class ur comparing the ids in the table but where ur getting the association id
June 17, 2014 at 1:47 am
$data=array(
'order_id'=>$this->input->post('order_id'),
'order_name'=>$this->input->post('order_name'),
'cat_id'=>$this->input->post('cat_id'),
'sub_cat_id'=>$this->input->post('sub_cat_id'),
);
$this->db->insert('order_master',$data);
}
Actually this is my code which i usedto add theorders can u make changes in this how to do that
June 17, 2014 at 1:47 am
ashalatha.cse76 (6/17/2014)
in where class ur comparing the ids in the table but where ur getting the association id
In the
SELECT values
FROM somewhere
part.
You actually have to fill in something yourself.
The code I gave was just mock-up code.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
June 17, 2014 at 1:47 am
$data=array(
'order_id'=>$this->input->post('order_id'),
'order_name'=>$this->input->post('order_name'),
'cat_id'=>$this->input->post('cat_id'),
'sub_cat_id'=>$this->input->post('sub_cat_id'),
);
$this->db->insert('order_master',$data);
}
Actually this is my code which i usedto add theorders can u make changes in this how to do that
it will be helpfull for me please
June 17, 2014 at 1:48 am
$data=array(
'order_id'=>$this->input->post('order_id'),
'order_name'=>$this->input->post('order_name'),
'cat_id'=>$this->input->post('cat_id'),
'sub_cat_id'=>$this->input->post('sub_cat_id'),
);
$this->db->insert('order_master',$data);
}
Actually this is my code which i usedto add theorders can u make changes in this how to do that
it will be helpfull for me please
June 17, 2014 at 1:49 am
ashalatha.cse76 (6/17/2014)
$data=array('order_id'=>$this->input->post('order_id'),
'order_name'=>$this->input->post('order_name'),
'cat_id'=>$this->input->post('cat_id'),
'sub_cat_id'=>$this->input->post('sub_cat_id'),
);
$this->db->insert('order_master',$data);
}
Actually this is my code which i usedto add theorders can u make changes in this how to do that
it will be helpfull for me please
Nope, sorry. First of all, I don't recognize the language and secondly I only do other peoples job when they pay me.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
June 17, 2014 at 1:50 am
k thanks
June 17, 2014 at 1:51 am
k no problem thanks
June 17, 2014 at 2:35 am
Hello,
The code looks like php
You'll have to construct a query with the where exist clause Koen mentioned.
Did some googlefu and ended up with:
June 17, 2014 at 3:40 am
ha it is in php
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply