Это позволит получить строки первых 3 ресурсов без необходимости самостоятельного объединения:
SQL Fiddle
MySQL 5.6 Настройка схемы :
CREATE TABLE table_name (
Name VARCHAR(20),
SomeData VARCHAR(20),
MoreStuff VARCHAR(20)
);
INSERT INTO table_name VALUES ( 'asset4', 'I need this', 'And also this' );
INSERT INTO table_name VALUES ( 'asset5', 'I need this', 'And also this' );
INSERT INTO table_name VALUES ( 'asset2', 'I need this', 'And also this' );
INSERT INTO table_name VALUES ( 'asset3', 'I need this', 'And also this' );
INSERT INTO table_name VALUES ( 'asset1', 'I need this', 'And also this' );
INSERT INTO table_name VALUES ( 'asset3', 'I need this', 'And also this' );
INSERT INTO table_name VALUES ( 'asset2', 'I need this', 'And also this' );
INSERT INTO table_name VALUES ( 'asset1', 'I need this', 'And also this' );
INSERT INTO table_name VALUES ( 'asset1', 'I need this', 'And also this' );
INSERT INTO table_name VALUES ( 'asset3', 'I need this', 'And also this' );
INSERT INTO table_name VALUES ( 'asset5', 'I need this', 'And also this' );
Запрос 1 :
SELECT Name, SomeData, MoreStuff
FROM (
SELECT @asset_num := IF( @prev_name = t.name, @asset_num, @asset_num + 1 ) AS an,
t.*,
@prev_name := Name
FROM table_name t
CROSS JOIN
( SELECT @prev_name := '', @asset_num := 0 ) r
ORDER BY Name
) t
WHERE an <= 3
Результаты :
| Name | SomeData | MoreStuff |
|--------|-------------|---------------|
| asset1 | I need this | And also this |
| asset1 | I need this | And also this |
| asset1 | I need this | And also this |
| asset2 | I need this | And also this |
| asset2 | I need this | And also this |
| asset3 | I need this | And also this |
| asset3 | I need this | And also this |
| asset3 | I need this | And also this |