0

I have this query and I know that I can't have limit clause in subquery for mysql is there anyway to write this in a correct syntax?

UPDATE:(SCENARIO)I want to maintain deleted visitors and when we want to select deleted visitors I should select distinct ips

$deletedvisitors = $wpdb->get_var("
       SELECT count(DISTINCT ip)
       FROM $table_name
       WHERE feed=''
       AND spider=''$normallimit AND id IN ( SELECT * FROM ". $table_name . " order by id limit $delneeded)");
Nickool
  • 3,662
  • 10
  • 42
  • 72

1 Answers1

0

You can create a subQuery and join on it according to this SO answer

SELECT count(DISTINCT ip)
FROM    (
    SELECT  *
    FROM ". $table_name . "
    LIMIT 10
    ) q
JOIN    $table_name
ON      q.id = $table_name.id
Community
  • 1
  • 1
Matt Busche
  • 14,216
  • 5
  • 36
  • 61