How to delete id from one table and id from another table if they are connected to one object?MySQL Error 1093 - Can't specify target table for update in FROM clauseHow to list the tables in a SQLite database file that was opened with ATTACH?How to return only the Date from a SQL Server DateTime datatypeHow to concatenate text from multiple rows into a single text string in SQL server?SQL update from one Table to another based on a ID matchHow do I connect to a MySQL Database in Python?How do I UPDATE from a SELECT in SQL Server?How to get the sizes of the tables of a MySQL database?How to delete a column from a table in MySQLHow to Delete using INNER JOIN with SQL Server?

Do French speakers not use the subjunctive informally?

Layout of complex table

STM Microcontroller burns every time

How many codes are possible?

Fedora boot screen shows both Fedora logo and Lenovo logo. Why and How?

MH370 blackbox - is it still possible to retrieve data from it?

Is this one of the engines from the 9/11 aircraft?

Could Sauron have read Tom Bombadil's mind if Tom had held the Palantir?

What does "THREE ALPHA in Virginia" mean?

What is this particular type of chord progression, common in classical music, called?

What is the line crossing the Pacific Ocean that is shown on maps?

Are Finite Automata Turing Complete?

First-year PhD giving a talk among well-established researchers in the field

How risky is real estate?

Analog is Obtuse!

Why does the A-4 Skyhawk sit nose-up when on ground?

Should I hide continue button until tasks are completed?

Is it possible to buy a train ticket CDG airport to Paris truly online?

What does 2>&1 | tee mean?

Was touching your nose a greeting in second millenium Mesopotamia?

Mount a folder with a space on Linux

Does the UK have a written constitution?

Should I tell my insurance company I'm making payments on my new car?

What determines the "strength of impact" of a falling object on the ground, momentum or energy?



How to delete id from one table and id from another table if they are connected to one object?


MySQL Error 1093 - Can't specify target table for update in FROM clauseHow to list the tables in a SQLite database file that was opened with ATTACH?How to return only the Date from a SQL Server DateTime datatypeHow to concatenate text from multiple rows into a single text string in SQL server?SQL update from one Table to another based on a ID matchHow do I connect to a MySQL Database in Python?How do I UPDATE from a SELECT in SQL Server?How to get the sizes of the tables of a MySQL database?How to delete a column from a table in MySQLHow to Delete using INNER JOIN with SQL Server?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have these two tables:



Table: REASON



id | name
---|------------
1 | gold_sell
2 | gold_buy
4 | Silver_sell


Table: REASON_TO_TRANSACTION



reason_id | transaction_type
----------|-------------------
1 | sell
2 | buy
4 | pko


where id from table reason is linked with reason_id from reason_to_transaction.



I want to delete all rows with id = 1 from these two tables.



Can someone help me?



I'm using SQL Server(phpmyadmin).



Variable name is for getting the current activeItem and delete it.



I have written following SQL command:



DELETE rt 
FROM reason_to_transaction rt
INNER JOIN reasons r
ON id=reason_id
WHERE reasons.id=reason_to_transaction.reason_id
AND name = 'gold_sell'


I also have this angular code:



$scope.deleteItem = function()
console.log($scope.activeItem);
var objectToSave =
name: $scope.activeItem.name,
id: $scope.activeItem.id
;

if($scope.activeItem.id)


defaultAdapter.query('DELETE rt FROM reason_to_transaction rt INNER JOIN reasons r ON r.id = tr.reason_id WHERE name = :name',
replacements: objectToSave, type: Sequelize.QueryTypes.UPDATE
).then(projects =>
console.log(projects);
$scope.editMode = false;
$scope.activeItem = false;
$scope.refresh();
);
else
defaultAdapter.query('DELETE rt FROM reason_to_transaction rt INNER JOIN reasons r ON r.id = tr.reason_id WHERE name = :name',

replacements: objectToSave, type: Sequelize.QueryTypes.UPDATE
).then(projects =>
console.log(projects);
$scope.editMode = false;
$scope.activeItem = false;
$scope.refresh();
);


;


And also have html submit form:



<div class="editMode1" style="display: none;">
<div class="form">
<form ng-submit="saveItem(reasonsForm.$valid)" name="reasonsForm">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="currency_code">Име на основание</label>
<input type="text" class="form-control" required ng-model="activeItem.name" placeholder="Име на основание за редактиране" />
</div>



</div>
</div>
<button class="btn btn-primary" ng-disabled="reasonsForm.$invalid" type="submit">Save</button>
<button class="btn btn-primary" type="submit" ng-click="deleteItem()">Delete</button> <!--ng-click="createUser()"-->

<button class="btn btn-primary" id="cnlbtn" type="button">Cancel</button>


</form>
</div>
</div>









share|improve this question
























  • @PranavCBalan this not work for me

    – Mitko
    Mar 25 at 9:11











  • what is rt is there any meaning of it ?

    – ali_codex
    Mar 25 at 9:38











  • @ali_codex it's a table alias

    – ADyson
    Mar 25 at 9:39











  • I'm using MySQL server(I'm coding on Angular with sequelize method for db). And using PhpMyAdmin

    – Mitko
    Mar 25 at 9:45











  • Sorry, but your question has nothing todo with angular ! Your problem is only linked to SQL ! So, if you agree with me, can you please adapt your question in removing 'Angular' and in adding that you are working with SQL Server ? Can you also specify which version ? Can you also correct your SQL command in removing second WHERE and in explaining what you want to do with :name variable ? This is not explain in your question ! Can you make all these changes directly in your question and not in comment so new reader are directly well informed. Thanks.

    – schlebe
    Mar 25 at 9:51

















0















I have these two tables:



Table: REASON



id | name
---|------------
1 | gold_sell
2 | gold_buy
4 | Silver_sell


Table: REASON_TO_TRANSACTION



reason_id | transaction_type
----------|-------------------
1 | sell
2 | buy
4 | pko


where id from table reason is linked with reason_id from reason_to_transaction.



I want to delete all rows with id = 1 from these two tables.



Can someone help me?



I'm using SQL Server(phpmyadmin).



Variable name is for getting the current activeItem and delete it.



I have written following SQL command:



DELETE rt 
FROM reason_to_transaction rt
INNER JOIN reasons r
ON id=reason_id
WHERE reasons.id=reason_to_transaction.reason_id
AND name = 'gold_sell'


I also have this angular code:



$scope.deleteItem = function()
console.log($scope.activeItem);
var objectToSave =
name: $scope.activeItem.name,
id: $scope.activeItem.id
;

if($scope.activeItem.id)


defaultAdapter.query('DELETE rt FROM reason_to_transaction rt INNER JOIN reasons r ON r.id = tr.reason_id WHERE name = :name',
replacements: objectToSave, type: Sequelize.QueryTypes.UPDATE
).then(projects =>
console.log(projects);
$scope.editMode = false;
$scope.activeItem = false;
$scope.refresh();
);
else
defaultAdapter.query('DELETE rt FROM reason_to_transaction rt INNER JOIN reasons r ON r.id = tr.reason_id WHERE name = :name',

replacements: objectToSave, type: Sequelize.QueryTypes.UPDATE
).then(projects =>
console.log(projects);
$scope.editMode = false;
$scope.activeItem = false;
$scope.refresh();
);


;


And also have html submit form:



<div class="editMode1" style="display: none;">
<div class="form">
<form ng-submit="saveItem(reasonsForm.$valid)" name="reasonsForm">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="currency_code">Име на основание</label>
<input type="text" class="form-control" required ng-model="activeItem.name" placeholder="Име на основание за редактиране" />
</div>



</div>
</div>
<button class="btn btn-primary" ng-disabled="reasonsForm.$invalid" type="submit">Save</button>
<button class="btn btn-primary" type="submit" ng-click="deleteItem()">Delete</button> <!--ng-click="createUser()"-->

<button class="btn btn-primary" id="cnlbtn" type="button">Cancel</button>


</form>
</div>
</div>









share|improve this question
























  • @PranavCBalan this not work for me

    – Mitko
    Mar 25 at 9:11











  • what is rt is there any meaning of it ?

    – ali_codex
    Mar 25 at 9:38











  • @ali_codex it's a table alias

    – ADyson
    Mar 25 at 9:39











  • I'm using MySQL server(I'm coding on Angular with sequelize method for db). And using PhpMyAdmin

    – Mitko
    Mar 25 at 9:45











  • Sorry, but your question has nothing todo with angular ! Your problem is only linked to SQL ! So, if you agree with me, can you please adapt your question in removing 'Angular' and in adding that you are working with SQL Server ? Can you also specify which version ? Can you also correct your SQL command in removing second WHERE and in explaining what you want to do with :name variable ? This is not explain in your question ! Can you make all these changes directly in your question and not in comment so new reader are directly well informed. Thanks.

    – schlebe
    Mar 25 at 9:51













0












0








0








I have these two tables:



Table: REASON



id | name
---|------------
1 | gold_sell
2 | gold_buy
4 | Silver_sell


Table: REASON_TO_TRANSACTION



reason_id | transaction_type
----------|-------------------
1 | sell
2 | buy
4 | pko


where id from table reason is linked with reason_id from reason_to_transaction.



I want to delete all rows with id = 1 from these two tables.



Can someone help me?



I'm using SQL Server(phpmyadmin).



Variable name is for getting the current activeItem and delete it.



I have written following SQL command:



DELETE rt 
FROM reason_to_transaction rt
INNER JOIN reasons r
ON id=reason_id
WHERE reasons.id=reason_to_transaction.reason_id
AND name = 'gold_sell'


I also have this angular code:



$scope.deleteItem = function()
console.log($scope.activeItem);
var objectToSave =
name: $scope.activeItem.name,
id: $scope.activeItem.id
;

if($scope.activeItem.id)


defaultAdapter.query('DELETE rt FROM reason_to_transaction rt INNER JOIN reasons r ON r.id = tr.reason_id WHERE name = :name',
replacements: objectToSave, type: Sequelize.QueryTypes.UPDATE
).then(projects =>
console.log(projects);
$scope.editMode = false;
$scope.activeItem = false;
$scope.refresh();
);
else
defaultAdapter.query('DELETE rt FROM reason_to_transaction rt INNER JOIN reasons r ON r.id = tr.reason_id WHERE name = :name',

replacements: objectToSave, type: Sequelize.QueryTypes.UPDATE
).then(projects =>
console.log(projects);
$scope.editMode = false;
$scope.activeItem = false;
$scope.refresh();
);


;


And also have html submit form:



<div class="editMode1" style="display: none;">
<div class="form">
<form ng-submit="saveItem(reasonsForm.$valid)" name="reasonsForm">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="currency_code">Име на основание</label>
<input type="text" class="form-control" required ng-model="activeItem.name" placeholder="Име на основание за редактиране" />
</div>



</div>
</div>
<button class="btn btn-primary" ng-disabled="reasonsForm.$invalid" type="submit">Save</button>
<button class="btn btn-primary" type="submit" ng-click="deleteItem()">Delete</button> <!--ng-click="createUser()"-->

<button class="btn btn-primary" id="cnlbtn" type="button">Cancel</button>


</form>
</div>
</div>









share|improve this question
















I have these two tables:



Table: REASON



id | name
---|------------
1 | gold_sell
2 | gold_buy
4 | Silver_sell


Table: REASON_TO_TRANSACTION



reason_id | transaction_type
----------|-------------------
1 | sell
2 | buy
4 | pko


where id from table reason is linked with reason_id from reason_to_transaction.



I want to delete all rows with id = 1 from these two tables.



Can someone help me?



I'm using SQL Server(phpmyadmin).



Variable name is for getting the current activeItem and delete it.



I have written following SQL command:



DELETE rt 
FROM reason_to_transaction rt
INNER JOIN reasons r
ON id=reason_id
WHERE reasons.id=reason_to_transaction.reason_id
AND name = 'gold_sell'


I also have this angular code:



$scope.deleteItem = function()
console.log($scope.activeItem);
var objectToSave =
name: $scope.activeItem.name,
id: $scope.activeItem.id
;

if($scope.activeItem.id)


defaultAdapter.query('DELETE rt FROM reason_to_transaction rt INNER JOIN reasons r ON r.id = tr.reason_id WHERE name = :name',
replacements: objectToSave, type: Sequelize.QueryTypes.UPDATE
).then(projects =>
console.log(projects);
$scope.editMode = false;
$scope.activeItem = false;
$scope.refresh();
);
else
defaultAdapter.query('DELETE rt FROM reason_to_transaction rt INNER JOIN reasons r ON r.id = tr.reason_id WHERE name = :name',

replacements: objectToSave, type: Sequelize.QueryTypes.UPDATE
).then(projects =>
console.log(projects);
$scope.editMode = false;
$scope.activeItem = false;
$scope.refresh();
);


;


And also have html submit form:



<div class="editMode1" style="display: none;">
<div class="form">
<form ng-submit="saveItem(reasonsForm.$valid)" name="reasonsForm">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="currency_code">Име на основание</label>
<input type="text" class="form-control" required ng-model="activeItem.name" placeholder="Име на основание за редактиране" />
</div>



</div>
</div>
<button class="btn btn-primary" ng-disabled="reasonsForm.$invalid" type="submit">Save</button>
<button class="btn btn-primary" type="submit" ng-click="deleteItem()">Delete</button> <!--ng-click="createUser()"-->

<button class="btn btn-primary" id="cnlbtn" type="button">Cancel</button>


</form>
</div>
</div>






mysql sql sql-delete






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 11:24







Mitko

















asked Mar 25 at 9:04









MitkoMitko

156 bronze badges




156 bronze badges












  • @PranavCBalan this not work for me

    – Mitko
    Mar 25 at 9:11











  • what is rt is there any meaning of it ?

    – ali_codex
    Mar 25 at 9:38











  • @ali_codex it's a table alias

    – ADyson
    Mar 25 at 9:39











  • I'm using MySQL server(I'm coding on Angular with sequelize method for db). And using PhpMyAdmin

    – Mitko
    Mar 25 at 9:45











  • Sorry, but your question has nothing todo with angular ! Your problem is only linked to SQL ! So, if you agree with me, can you please adapt your question in removing 'Angular' and in adding that you are working with SQL Server ? Can you also specify which version ? Can you also correct your SQL command in removing second WHERE and in explaining what you want to do with :name variable ? This is not explain in your question ! Can you make all these changes directly in your question and not in comment so new reader are directly well informed. Thanks.

    – schlebe
    Mar 25 at 9:51

















  • @PranavCBalan this not work for me

    – Mitko
    Mar 25 at 9:11











  • what is rt is there any meaning of it ?

    – ali_codex
    Mar 25 at 9:38











  • @ali_codex it's a table alias

    – ADyson
    Mar 25 at 9:39











  • I'm using MySQL server(I'm coding on Angular with sequelize method for db). And using PhpMyAdmin

    – Mitko
    Mar 25 at 9:45











  • Sorry, but your question has nothing todo with angular ! Your problem is only linked to SQL ! So, if you agree with me, can you please adapt your question in removing 'Angular' and in adding that you are working with SQL Server ? Can you also specify which version ? Can you also correct your SQL command in removing second WHERE and in explaining what you want to do with :name variable ? This is not explain in your question ! Can you make all these changes directly in your question and not in comment so new reader are directly well informed. Thanks.

    – schlebe
    Mar 25 at 9:51
















@PranavCBalan this not work for me

– Mitko
Mar 25 at 9:11





@PranavCBalan this not work for me

– Mitko
Mar 25 at 9:11













what is rt is there any meaning of it ?

– ali_codex
Mar 25 at 9:38





what is rt is there any meaning of it ?

– ali_codex
Mar 25 at 9:38













@ali_codex it's a table alias

– ADyson
Mar 25 at 9:39





@ali_codex it's a table alias

– ADyson
Mar 25 at 9:39













I'm using MySQL server(I'm coding on Angular with sequelize method for db). And using PhpMyAdmin

– Mitko
Mar 25 at 9:45





I'm using MySQL server(I'm coding on Angular with sequelize method for db). And using PhpMyAdmin

– Mitko
Mar 25 at 9:45













Sorry, but your question has nothing todo with angular ! Your problem is only linked to SQL ! So, if you agree with me, can you please adapt your question in removing 'Angular' and in adding that you are working with SQL Server ? Can you also specify which version ? Can you also correct your SQL command in removing second WHERE and in explaining what you want to do with :name variable ? This is not explain in your question ! Can you make all these changes directly in your question and not in comment so new reader are directly well informed. Thanks.

– schlebe
Mar 25 at 9:51





Sorry, but your question has nothing todo with angular ! Your problem is only linked to SQL ! So, if you agree with me, can you please adapt your question in removing 'Angular' and in adding that you are working with SQL Server ? Can you also specify which version ? Can you also correct your SQL command in removing second WHERE and in explaining what you want to do with :name variable ? This is not explain in your question ! Can you make all these changes directly in your question and not in comment so new reader are directly well informed. Thanks.

– schlebe
Mar 25 at 9:51












0






active

oldest

votes














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%2f55334328%2fhow-to-delete-id-from-one-table-and-id-from-another-table-if-they-are-connected%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















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%2f55334328%2fhow-to-delete-id-from-one-table-and-id-from-another-table-if-they-are-connected%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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현