Solved

error in sql sentence

Posted on 2014-07-30
6
239 Views
Last Modified: 2014-07-30
I have this sql sentence

DELETE laterales, actividad, registro, 
                   areas, sede_hoteles, sede, anteriores, banners,
				   evento_conferencistas, programa, configuracion, subdominios FROM subdominios
               JOIN anteriores ON anteriores.clave=subdominios.clave
               JOIN sede_hoteles ON sede_hoteles.evento=subdominios.clave			   
			   JOIN evento_conferencistas ON evento_conferencistas.evento=subdominios.clave
			   JOIN programa ON programa.clave=subdominios.clave
			   JOIN banners ON banners.evento=subdominios.clave
			   JOIN configuracion ON configuracion.clave=subdominios.clave 
			   JOIN registro ON registro.clave=subdominios.clave 
			   JOIN areas ON areas.principal=subdominios.clave
			   JOIN sede ON sede.clave=subdominios.clave   				   
			   INNER JOIN actividad ON actividad.principal=registro.clave			   
			   INNER JOIN laterales ON laterales.principal=registro.oculto OR laterales.principal = areas.clave      
			   WHERE subdominios.clave='36114165614'

Open in new window


This sentence works without problem when it found data in all my tables, but when it doesnt find data in some of this tables the sql sentence did not delete anything.

What Im doing wrong?

What changes do I need to do to allow it to work in all cases
0
Comment
Question by:altariamx2003
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 13

Assisted Solution

by:Russell Fox
Russell Fox earned 250 total points
ID: 40230638
You don't need any of those joins. What's happening is something in record #36114165614 is missing from one of the joined tables. For example, if there's no banners.evento that matches the subdominos.clave, the query will come up blank. Remember that "JOIN" is the same as "INNER JOIN" - inner join is the default. This code will just delete record #36114165614 from anteriores:
DELETE 
FROM subdominios
WHERE subdominios.clave='36114165614'

Open in new window

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 40230706
Perhaps the author only wants to delete rows when there is a match to all those tables.  But if that is not the case than I agree that you should not need them.
0
 

Author Comment

by:altariamx2003
ID: 40230811
Thats right the idea of that query is that eliminate all rows in all tables that match with the criteria
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 250 total points
ID: 40230823
So then the answer to your question "What Im doing wrong?"  is nothing.

In other words this:
"when it doesnt find data in some of this tables the sql sentence did not delete anything."
matches this:
"Thats right the idea of that query is that eliminate all rows in all tables that match with the criteria"
0
 

Author Comment

by:altariamx2003
ID: 40230830
What I was trying to do it is delete rows of the tables in my query when matches with the criteria, but the problem is that it only works when in all tables there are rows that matches.

But anyway Im gonna dropped this query and use on cascade, perhaps that will be more easy
0
 

Author Comment

by:altariamx2003
ID: 40230831
thanks anyway for your time

best regards
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question