Solved

error in sql sentence

Posted on 2014-07-30
6
233 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

747 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

9 Experts available now in Live!

Get 1:1 Help Now