Delete query (more relation between table)


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Delete query (more relation between table)

  1. #1
    Join Date
    Jun 2004
    Posts
    19

    Delete query (more relation between table)

    Hi Everyone,

    I have a problem to delete record in Table A, since the table have relation to Table B. For example,

    Table A = StudentMarks
    StudentID SubjectMarks
    1 50
    2 77
    3 100

    Table B = StudentData
    StudentID Name Class
    1 John 1A
    2 Calvin 1A
    3 Kelly 2B

    * I want to delete the StudentMarks in class 1A. The "StudentID" is the foreign key which related to TableB to get the "Class".

    Is it possible to do that? Any help will be appreciate.

    Calvin

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    So, you want to delete the marks, but leave the StudendID in place with all the remaining fields blank?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Jun 2004
    Posts
    19
    No, I want to delete the whole record including the student ID. This two record are totally delete.

    1 50
    2 77

  4. #4
    Join Date
    Feb 2008
    Posts
    162
    Try:

    DELETE FROM TableA
    WHERE EXISTS
    (
    SELECT *
    FROM TableB
    WHERE TableA.StudentID = TableB.StudentID
    AND TableB.Class = '1A'
    )
    It's not what you don't know that gets you in trouble. It's what you know that just ain't so. -Mark Twain

  5. #5
    Join Date
    Jun 2004
    Posts
    19

    Thumbs up

    It works

    Thank you very much

Similar Threads

  1. SQL Many Table Relation
    By sa in forum .NET
    Replies: 2
    Last Post: 08-07-2002, 03:20 PM
  2. reg...select count distinct....query
    By Mohan Ekambaram in forum Database
    Replies: 0
    Last Post: 12-09-2001, 12:56 PM
  3. reg....count distinct query
    By Mohan Ekambaram in forum Database
    Replies: 0
    Last Post: 12-09-2001, 12:21 AM
  4. Returning errors from SQL Server Stored Procs
    By Khalizan in forum VB Classic
    Replies: 1
    Last Post: 11-28-2001, 02:32 AM
  5. Replies: 1
    Last Post: 11-20-2001, 03:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center