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 8468735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:01:12+00:00 2026-06-10T16:01:12+00:00

I was given this MySQL Interview Question, which made me disqualified for the job.

  • 0

I was given this MySQL Interview Question, which made me disqualified for the job.

I went to interview and was asked a question which I was not able to reply and I lost the job.

They asked.

We have two tables, the first table (master table) is CANDIDATES with fields:

  • candidate_id (primary_key)
  • candidate_name

The Second table (child table) is CANDIDATE_VOTES with fields:

  • v_id (primary key)
  • candidate_id (foreign key)

Every time a vote is given the candidate’s candidate_key is put in the child.

CANDIDATE:

=================================     
|candidate_id | candidate_Name  |  
|-------------------------------|  
| 1           | abc             |  
|-------------------------------|  
| 2           | xyz             |  
|-------------------------------|  
| 3           | etc             |  
|-------------------------------|  

CANDIDATE VOTES

==========================     
| votes_id | candidate_id |  
|-------------------------|  
| 1        | 1            |  
|-------------------------|  
| 2        | 1            |  
|-------------------------|  
| 3        | 2            |  
|-------------------------| 

The Question was how would you declare a winner?

Please help me how to do it.

I tried a lot but could not find the logic.

  • 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-10T16:01:13+00:00Added an answer on June 10, 2026 at 4:01 pm

    You should return all candidates who have the most number of votes:

    SELECT   candidates.*
    FROM     candidates JOIN candidate_votes USING (candidate_id)
    GROUP BY candidate_id
    HAVING   COUNT(*) = (
      SELECT   COUNT(*)
      FROM     candidate_votes
      GROUP BY candidate_id
      ORDER BY votes DESC
      LIMIT    1
    )
    

    See it on sqlfiddle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this JavaScript code (which is just a comment referring to a url): //
I have the same tables as in this question: MySql query over many-to-many relationship
Basically I want to be able to invoke a given command, in this case
Given this MySQL stored procedure: CREATE PROCEDURE customer.`getCustomers5`( sdf varchar(1000) ) BEGIN set @se
Given this table : mysql> describe activity; +---------------------------+-------------+------+-----+---------+-------+ | Field | Type | Null
I have a MySQL database table with this structure: table id INT NOT NULL
Someone I know went to an interview and was given the following problem to
i have this code which is not seeming to work, what i want to
Possible Duplicate: mysql_fetch_array() expects parameter 1 to be resource, boolean given in select This
Given this method to work on a HTML page in a webbrowser: bool semaphoreForDocCompletedEvent;

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.