Solved

error in sql sentence

Posted on 2014-07-30
6
238 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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 INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

696 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