KeyConditionExpression can only be applied to partition and optionally to sort key. The documentation states the following.
Use the KeyConditionExpression parameter to provide a specific value for the partition key. The Query operation will return all of the items from the table or index with that partition key value. You can optionally narrow the scope of the Query operation by specifying a sort key value and a comparison operator in KeyConditionExpression.
The same documentation continues with
To further refine the Query results, you can optionally provide a FilterExpression. A FilterExpression determines which items within the results should be returned to you. All of the other results are discarded.
Thus you can use FilterExpression to narrow the result set more, which might provide support for your second use case.
If this is not enough, you'll probably need to look into using indexes, Global Secondary Index (GSI) spefically. Basically an index will create another table with different keys. To support your second requirement, I think the following GSI structure could work.
name | code
-----------
PRD | 425
PRD | 456
PRD | 427
....
Where name is partition key amd code is sort key. But these attribute pairs need to always constitute an unique primary key for each record, otherwise you cannot use this structure.
Addendum: After reviewing my post and re-reading your question, I realized that you do not have separate name and code attributes, but a single attribute with data such as "PRD 425" and "PRD 426". I have no experience on this. The Query documentation again says the following about KeyConditionExpression
The condition that specifies the key value(s) for items to be retrieved by the Query action.
The condition must perform an equality test on a single partition key value.
The condition can optionally perform one of several comparison tests on a single sort key value. This allows Query to retrieve one item with a given partition key value and sort key value, or several items that have the same partition key value but different sort key values.
My understanding on this is that you cannot limit it the way required.
Addendum 2: After more thought, I remembered that DynamoDB documentations commonly suggest a strategy where the partition key is suffixed with random numbers for example. Unfortunately I don't have details on how to perform queries against that schema, but it should give you hints on organizing your data.