Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete row if exists

Tags:

mysql

joomla

DELETE IF EXIST `#__menu`.*
FROM `#__menu` 
LEFT JOIN `#__extensions` ON `#__extensions`.`name` = 'com_view' 
WHERE `#__menu`.`component_id` = `#__xtensions`.`extension_id`
AND `#__menu`.`alias` = 'view-sites' AND `#__menu`.`path` = 'view-sites' AND `#__menu`.`title` = 'View sites';

What is wrong in my sql? I think the problem is in IF EXIST, but i could not figure out how to use it on row.

like image 525
Kin Avatar asked Oct 12 '12 13:10

Kin


People also ask

How to delete a row in Excel with Yes/No column?

Follow the following steps: 1 Step 1: Select your Yes/No column 2 Step 2: Press Ctrl + F value 3 Step 3: Search for No value 4 Step 4: Click on Find All 5 Step 5: Select all by pressing Ctrl + A 6 Step 6: Right-click on any No value and press Delete 7 Step 7: A dialogue box will open 8 Step 8: Select Entire Row 9 Step 9: Click OK More ...

How to remove rows if contains value from the remove list?

Remove rows if contains value from the remove list with Kutools for Excel. If you have Kutools for Excel – a handy multi-functional tool, you can quickly find the rows which contain values from the other list by Select Same & Different Cells feature and then remove them by yourself.

How to delete entire row based on condition in Excel VBA?

Delete entire row based on condition with Excel VBA: Step 1: Go to Visual Basic page Step 2: Press Alt + F11 Step 3: Click Insert > Module > New Module Step 4: Paste the code in the new module Step 5: Press F5 to run the code Step 6: The input box will appear to input the value you need to delete ...

How to check if a row is deleted or not?

If you do not have a flag or value that you can check to see if it is to be deleted, you could use an Exists transformation to look for rows that are not present in the source compared to rows in your target and set those rows for delete. Comment Comment · Show 3 Comment 5 |1600characters neededcharacters leftcharacters exceeded


Video Answer


1 Answers

When you're deleting rows from a table, you don't need to use IF EXISTS - you're using a WHERE clause, so if it exists - it will be deleted.

Try changing your query to:

DELETE
FROM `#__menu` 
LEFT JOIN `#__extensions` ON `#__extensions`.`name` = 'com_view' 
WHERE `#__menu`.`component_id` = `#__xtensions`.`extension_id`
AND `#__menu`.`alias` = 'view-sites' AND `#__menu`.`path` = 'view-sites' AND `#__menu`.`title` = 'View sites';

Also, you don't need to specify ```#__menu.*`` (the columns) to be deleted - you'll just needDELETE FROM...`. Check out here for more info regarding the syntax.

like image 133
newfurniturey Avatar answered Sep 30 '22 04:09

newfurniturey