PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table materials ( name varchar(32), material_group int, price int ); insert into materials values ('one', 1, 200), ('two', 2, 200), ('three', 1, 100), ('four', 1, 90), ('five', 1, 130), ('six', 1, 25), ('seven', 1, 900) ;
Copy Clear
Copy Format Clear
<?php $query = " SELECT materials.* FROM materials JOIN ( SELECT material_group, MIN(price) chipest_price FROM materials GROUP BY material_group ) chipest ON chipest.material_group = materials.material_group AND chipest_price = price;"; $stmt = $pdo->prepare($query); $stmt->execute(); $rows = $stmt->fetchALL(PDO::FETCH_ASSOC); var_export($rows);
Show:  
Copy Clear