I have workshops that have manufacturers, one workshop can have many manufacturers, but only one official. I want to get all workshops that have manufacturer 22 but if they have same vat only get workshop who manufacturer is offical

I have 2 tables, first workshop

```
id | name          | vat
-------------------------
 1 | name 1        | B12
 2 | name 2        | B12
 3 | name 3        | B12
 4 | name 4        | E98
 5 | name 5        | A99

```

second workshop\_manufacturer

```
id | workshop_id | manufacturer_id  | official
----------------------------------------------
 1 | 1           | 22               | 0               
 2 | 2           | 22               | 0
 3 | 3           | 22               | 1
 4 | 4           | 22               | 0
 5 | 5           | 22               | 1
 5 | 5           | 23               | 0
 5 | 5           | 24               | 0

```

I want to get unique workshops (group by vat) but I want to get the official one (official=1) if there are many workshop with same vat who work with this manufacturer.

If I do this query:

```
SELECT t1.*,t2.* FROM workshop t1
INNER JOIN workshop_manufacturer t2 ON t1.id=t2.workshop_id
WHERE t2.manufacturer.id = 22
GROUP bY t1.vat

```

I get this:

```
id | name    | vat  | official | manufacturer_id 
-----------------------------------------------
 1 | name 1  | B12  | 0       | 22
 4 | name 4  | E98  | 0       | 22
 5 | name 5  | A99  | 1       | 22

```

and I want this:

```
id | name    | vat  | official | manufacturer_id 
-----------------------------------------------
 3 | name 3  | B12  | 1      | 22
 4 | name 4  | E98  | 0      | 22
 5 | name 5  | A99  | 1      | 22

```

All the workshops who are official and non official but giving priority that ones who are official