Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8537757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:58:35+00:00 2026-06-11T10:58:35+00:00

I have a table named as Team_table having a column Team_Id as a primary

  • 0

I have a table named as Team_table having a column Team_Id as a primary key, and 4 different table are Team_Member, Team_Project, Team_Account, Team_link also contains this Team_Id.

Before deleting a team from Team_table, I have to check its reference in all 4 tables. if this Team_Id found in any one table, user cant delete it.

I made following query but its not working-

select count(Team.Team_Id)
  from Team 
  join Team_Project on Team.Team_Id = Team_Project.Team_Id  
 right join Team_Member on Team.Team_Id = Team_member.Team_Id  
 right join Team_link on Team.Team_Id = Team_link.Team_Id  
 right join Team_Account on Team.Team_Id = Team_Account.Team_Id  
 where Team.Team_Id = 2

But its always giving me 0, while this team_Id is available in all tables.
Please suggest me right solution

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:58:36+00:00Added an answer on June 11, 2026 at 10:58 am

    A group of right join ends up empty the last table is empty. A group of left join ends up empty if the first table is empty. But a group of full join will return any matching rows. So consider replacing your right join with full join.

    As another option, I find it clearer to use not exists clauses instead of join for this kind of query:

    delete  t
    from    Team t
    where   t.Team_Id = @TeamId
            and not exists (select * from Team_Project where Team_Id = @TeamId)
            and not exists (select * from Team_Member where Team_Id = @TeamId)
            and not exists (select * from Team_link where Team_Id = @TeamId)
            and not exists (select * from Team_Account where Team_Id = @TeamId)
    

    Per your comment, to retrieve the count:

    select  count(*)
    from    (
            select  Team_Id 
            from    Team_Project 
            union all
            select  Team_Id 
            from    Team_Member  
            union all
            select  Team_Id 
            from    Team_link    
            union all
            select  Team_Id 
            from    Team_Account 
            ) as SubQueryAlias
    where   Team_Id = @TeamId
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table named stats player_id team_id match_date goal assist` 1 8 2010-01-01
I have a table named with Sales having the following columns: Sales_ID|Product_Code|Zone|District|State|Distributor|Total_Sales Now i
Lets say I have table named Place with columns: placeId int not null auto_increment,
I have a table named tbl_Subjects_Taken which lists all the subjects taken by the
I have a table named datas and I'm executing a query like this: SELECT
I have a table named size here, something like this: size id | size
I have a table named scores with the columns id and score . I
I have two tables: players (has a team name column) and teams (also has
I have on table named players , then other tables named tries , conversions
I am trying to test some DAOs. I have Entity (and table) named Nomination

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.