views:

29

answers:

2

Hi,

I wanna to have query:

Select cars.* from cars where cars.code in
(
select carCode from articles where 
numberofrecords with this car (it is not a column) >1
and Accepted=1
order by date
)

How to write it?

+2  A: 

Try something like this:

SELECT  cars.*
FROM    cars
WHERE   cars.code IN (
    SELECT  carCode
    FROM    articles
    WHERE   Accepted = 1
    GROUP BY carCode
    HAVING COUNT(articleId) > 1
)
David M
+2  A: 

This should do it:

SELECT c.*
FROM cars c
    JOIN
    (
        SELECT carCode 
        FROM articles
        WHERE Accepted = 1
        GROUP BY carCode
        HAVING COUNT(carCode) > 1
    ) a ON c.code = a.carCode
AdaTheDev