0

I need help

I need to run a sql query to " list all the cars that have been sold more than once". Tables Include: VEHICLE SALES PERSON SALES DETAILS CUSTOMER I have a feeling i need to use a DISTINCT command? I have tried the following SELECT v.make, sd.reg_no FROM vehicle v, salesdetail sd WHERE sd.reg_no = *sd.date_sold GROUP BY sd.date_sold; came up with multiple errors..... any ideas?

24th Jan 2017, 9:43 AM
Winiata Hunia
Winiata Hunia - avatar
5 Answers
+ 1
Please provide the structure of the tables you need to query
24th Jan 2017, 1:07 PM
Lavish Thomas
Lavish Thomas - avatar
+ 1
SELECT reg_no, COUNT(reg_no) FROM salesdetail HAVING COUNT(reg_no) >1 GROUP BY reg_no ORDER BY COUNT(reg_no) DESC; Thanx people i figured it out......😆
25th Jan 2017, 9:34 AM
Winiata Hunia
Winiata Hunia - avatar
0
You can try to use inner join instead because I am not sure if you can write 2 tables directly after 'FROM' SELECT v.make, sd.reg_no FROM vehicle v INNER JOIN salesdetail sd ON (you should probably show how vehicle and salesdetail table are linked) GROUP BY sd.date_sold; Not sure if this will give you any syntax error though
24th Jan 2017, 10:00 AM
lowshuen
0
How do you sell a car more than once? Perhaps something is inheritedly wrong with the question.
24th Jan 2017, 10:20 AM
Abe Shudug
Abe Shudug - avatar
0
u can use "," after FROM for joining two tables with outer join
24th Jan 2017, 1:09 PM
Lavish Thomas
Lavish Thomas - avatar