I am trying to create a view based on the following mySQL table:
+------------------------+---------------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+---------------------+------+-----+-------------------+-----------------------------+
| id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| idPartner | int(10) unsigned | NO | MUL | NULL | |
| sBrand | varchar(512) | YES | | NULL |
I would like distinct id sBrand and idPartner values, calling something like this:
CREATE VIEW VBrand As select distinct sBrand, id, idPartner from tblProduct;
However, I need to also include a primary key to satisfy the retrieving API resource. Including 'id' w/ DISTINCT will not work.
My first thought is to query DISTINCT, then ALTER VIEW to tack on an id column, but apparently in order to edit a view you need to re-instantiate the original CREATE commands, thus rendering the whole effort pointless. All other solutions I have seen online (ie PARTITION, ORDER_BY) are for other versions of SQL.
Edit: I want to output unique values for partner and brand, ie:
+-------------------+-----------+
| sBrand | idPartner |
+-------------------+-----------+
| PLANTERS | 45933 |
| SARGENTO | 45913 |
| TOTINOS | 45933 |
| TRU MOO | 45930 |
| VANITY FAIR | 45913 |
But due to controller design, an id is expected. In effect I want to add id as an ancillary column to (distinct) sBrand and idPartner. However this is not possible in the DISTINCT query. Ideal output something like this:
+----------+----------+-----------+
| sBrand | id | idPartner |
+----------+----------+-----------+
| TOTIN | 13774056 | 45933 |
| PLANTERS | 13774362 | 45913 |
| SARGENT | 13774430 | 45933 |
| YOPL | 13774764 | 45930 |
| APPL | 13774768 | 45913 |