Skip to main content
February 4, 2008
Question

SQL problem

  • February 4, 2008
  • 2 replies
  • 385 views
Hi there,

I'm trying to display vacancies which have applications that have an interview status of 1. The problem is its displaying duplicate listings based on the number of applications per vacancy. E.G if a vacancy has 3 applications then it shows the vacancy 3 times, where I just want to show it once. I tried using distinct in the query but it didnt seem to change it.

select distinct(vacancyId), v.id as VACID, title, clientId, v.status, c.id, c.companyname, candVacDate as THEDATE, c.county, c.town, adminID, v.location, interview
from vacancies as v
inner join clients as c
on (v.clientId = c.id)
inner join candVac as cv
on (v.id = cv.vacancyId)
where interview = 1;

I've probably missed something, don't hesitate to ask for more info!

Any help is appreciated.

Cheers - Jared.
    This topic has been closed for replies.

    2 replies

    February 5, 2008
    Hi - thanks for the speedy replies, I didnt think about the group by - I just added that to the cfoutput and it worked fine!!

    You were both right it was due to multiple client apps, I was blocked on the group by.... gota love coding sometimes.

    I would've thought that I could've added that to the actual sql query though but that didnt work? Any ideas on that?

    Cheers - Jared.
    Inspiring
    February 5, 2008
    quote:

    Originally posted by: plasmoid
    Hi - thanks for the speedy replies, I didnt think about the group by - I just added that to the cfoutput and it worked fine!!

    You were both right it was due to multiple client apps, I was blocked on the group by.... gota love coding sometimes.

    I would've thought that I could've added that to the actual sql query though but that didnt work? Any ideas on that?

    Cheers - Jared.

    If you are selecting aggregates, you have to group by every normal field in your select clause. The more fields you have, the more records you are going to get back. That's the way it goes.
    Inspiring
    February 4, 2008
    You are getting multiple records because the applications for each vacancy are probably by different clients. Since you appear to need that data, look at the group attribute of cfoutput to change your display.
    Participating Frequently
    February 4, 2008
    Along the lines of what Dan said, since you probably need all of the other data selected in your query, you may try using a query-of-query to select your DISTINCT vacancyId where interview = 1. That way, your original query gives you all of your client data for your vacancies, but the Q-of-Q will give you a separate list of unique vacancies if you need that.

    Phil