Solved

error in sql sentence

Posted on 2014-07-30
6
237 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

792 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