Solved

error in sql sentence

Posted on 2014-07-30
6
235 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
  • 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use Full Text CONTAINS with Case in SQL 6 19
Sql query 107 29
Join multiple pivot queries 2 8
Trouble analysing a database 9 14
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now