I have the following file_tbl
table:
id fname fdescription ftype fsize wbsid timestamp
And I do no not want to select duplicate rows with same fname and wbsid, but same fname and different wbsid shall be selected.
my query:
$stmt = $pdo->prepare("SELECT DISTINCT(fname), wbsid from file_tbl ORDER BY wbsid ASC");
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
echo'<hr>file-name:'.$row['fname'];
echo'<br>file-description:'.$row['fdescription'];
echo'<br>file-wbs-id:'.$row['wbsid'];
echo'<br>file-wbs-id:'.$row['timestamp'];
}
- This will cause a Notice: Undefined index: fdescription, timestamp in ... on line ...
the query is working for the distinct, but I need all the columns to be fetched - and I do not know how to SELECT all of them without destroying the query. (I made a lot trials with JOIN and GROUP BY, but nothing worked for me - eg this solution does not meet my requirements: Select distinct column along with some other columns in MySQL)
notice: I created the timestamp via PHP , its a (varchar) if this is of any interest.
My approach now is to bring two SELECT queries from the same table together - unfortunately I wasn't able to accomplish this yet. (INNER JOIN; LEFT JOIN; some sorts of subqueries (http://www.w3resource.com/mysql/subqueries/index.php) ...
edit: a working sql-fiddle is now available - its working fine there, but not on my own LAMP-stack: http://sqlfiddle.com/#!9/95bad/1 or, the copy-pasted original with InnoDB and latin1: http://sqlfiddle.com/#!9/b3bce0/2