<?php
require_once 'config/database.php';
$db = getDB();

// Check duplicates
$sql = 'SELECT cl.id, cl.title, cl.module_id, cl.topic_id 
FROM course_modules cm 
LEFT JOIN course_topics ct ON cm.id = ct.module_id 
LEFT JOIN course_lessons cl ON (ct.id = cl.topic_id OR (cl.topic_id IS NULL AND cl.module_id = cm.id)) 
WHERE cm.course_id = 14';
$r = $db->query($sql)->fetchAll(PDO::FETCH_ASSOC);
echo "Rows returned: " . count($r) . "\n";
echo "Unique lesson IDs: " . count(array_unique(array_column($r, 'id'))) . "\n";

// Show first few
foreach (array_slice($r, 0, 10) as $i => $row) {
    echo "Row $i: lesson_id=" . $row['id'] . " module_id=" . $row['module_id'] . " topic_id=" . $row['topic_id'] . "\n";
}