-1

i had this error when i used this query

   SELECT id,title,files,price,auction_start,
   (SELECT * FROM `phi_files` where  id in(d.files) order by id desc limit 1)
   FROM phi_ads d Where cat=1 GROUP BY id DESC Limit 6

I have two table phi_ads table have ads , and phi_files have images files , i try to take one file for each ad

any help

2 Answers2

0

As I see the id is duplicate in both table try in sub select phi_files.id

SELECT id,title,files,price,auction_start,
   (SELECT * FROM `phi_files` where  phi_files.id in(phi_ads.files) order by phi_files.id desc limit 1)
   FROM phi_ads Where cat=1 GROUP BY id DESC Limit 6
ferhado
  • 2,363
  • 2
  • 12
  • 35
0

When a subquery is used as an expression, it can only return one value. So the query has to return a single row, and that row has to have a single column.

You solved the multiple row problem by using LIMIT 1. To solve the multiple column problem, change * to the specific column that you need.

I also wonder why you're using WHERE id IN (d.files). Since there's only one value in the list, it should be WHERE id = d.files. Or if d.files is a comma-separated list (as I suspect from the column name), you need to use WHERE FIND_IN_SET(id, d.files). See Query with multiple values in a column.

Barmar
  • 741,623
  • 53
  • 500
  • 612