# Why does Select not work here?

Why does this not work? It returns empty while I expect the first two elements are selected.

Select[{{x1, ConditionalExpression[1, 1 <= t <= 5]}, {y1,
ConditionalExpression[1, 1 <= t <= 5]}, {y1,
ConditionalExpression[1, t >= 1]}}, #[[2]] ==
ConditionalExpression[1, 1 <= t <= 5] &]


Also, how can I include the third element here?

Select[{{x1, ConditionalExpression[1, 1 <= t <= 5]}, {y1,
ConditionalExpression[1, 1 <= t <= 5]}, {y2,
ConditionalExpression[1, t >= 1 && t <= 5]}, {y1,
ConditionalExpression[1, t >= 1]}}, #[[2]] ==
ConditionalExpression[1, 1 <= t <= 5] &]


Edit 3

I am not explaining the logic again, as it is explained below, but this is much cleaner.

This is the second example

list = {{x1, ConditionalExpression[1, 1 <= t <= 5]}, {y1,
ConditionalExpression[1, 1 <= t <= 5]}, {y2,
ConditionalExpression[1, t >= 1 && t <= 5]}, {y1,
ConditionalExpression[1, t >= 1]}};
rule = {ConditionalExpression[1, 1 <= t <= 5] -> x,
ConditionalExpression[1, t >= 1 && t <= 5] -> y};
invrule = Map[Reverse, rule];

Select[list /. rule, ContainsAny[Join[{x, y}]]] /. invrule


Edit 2

In more complicated situations, where the rules do not combine nicely, you can create two separate ones, select them individually and join the list. Like so:

list = {{x1, ConditionalExpression[1, 1 <= t <= 5]}, {y1,
ConditionalExpression[1, 1 <= t <= 5]}, {y2,
ConditionalExpression[1, t >= 1 && t <= 5]}, {y1,
ConditionalExpression[1, t >= 1]}};
rule = {ConditionalExpression[1, 1 <= t <= 5] -> x,
ConditionalExpression[1, t >= 1 && t <= 5] -> y};
invrule = Map[Reverse, rule];


then

Join[Select[list /. rule, #[[2]] == x &],
Select[list /. rule, #[[2]] == y &]] /. invrule


Edit 1

You can use the following to invert the rule

list = {{x1, ConditionalExpression[1, 1 <= t <= 5]}, {y1,
ConditionalExpression[1, 1 <= t <= 5]}, {y1,
ConditionalExpression[1, t >= 1]}};
rule = {ConditionalExpression[1, 1 <= t <= 5] -> x};
invrule = Map[Reverse, rule];


and then

Select[list /. rule, #[[2]] == x &] /. invrule


And for the second example

list = {{x1, ConditionalExpression[1, 1 <= t <= 5]}, {y1, ConditionalExpression[1, 1 <= t <= 5]}, {y2, ConditionalExpression[1, t >= 1 && t <= 5]}, {y1, ConditionalExpression[1, t >= 1]}}; rule = {ConditionalExpression[1, 1 <= t <= 5] -> x, ConditionalExpression[1, t >= 1 && t <= 5] -> x}; invrule = Map[Reverse, rule];

and then

Select[list /. rule, #[[2]] == x &] /. invrule


gives

Original

@Nasser gave one way, here's another. Set the condition you want to pick to be x using a rule.

list = {{x1, ConditionalExpression[1, 1 <= t <= 5]}, {y1,
ConditionalExpression[1, 1 <= t <= 5]}, {y1,
ConditionalExpression[1, t >= 1]}};
rule = ConditionalExpression[1, 1 <= t <= 5] -> x;
invrule = x -> ConditionalExpression[1, 1 <= t <= 5];


and then

Select[list /. rule, #[[2]] == x &] /. invrule


while I expect the first two elements are selected.

Use === and not ==

Select[{
{x1, ConditionalExpression[1, 1 <= t <= 5]},
{y1, ConditionalExpression[1, 1 <= t <= 5]},
{y1, ConditionalExpression[1, t >= 1]}},
#[[2]] === ConditionalExpression[1, 1 <= t <= 5] &]


how can I include the third element here?

Ok, I found why Select does not find y2 for your second question. It is more subtle than I first thought it is.

To see why, it is due to the difference between ConditionalExpression[1, t >= 1 && t <= 5] and ConditionalExpression[1, 1 <= t <= 5]. We see the following

That is why Select did not find the third entry. It is not the same!

Internally one is Inequality and the other is not. Hence did not select it. One workaround is to first change the Inequality like this and then call Select

expr = {{x1, ConditionalExpression[1, 1 <= t <= 5]},
{y1, ConditionalExpression[1, 1 <= t <= 5]},
{y2, ConditionalExpression[1, t >= 1 && t <= 5]},
{y1, ConditionalExpression[1, t >= 1]}};
expr = expr /. Inequality[a_, LessEqual, b_, LessEqual, c_] :> a <= b <= c;
Select[expr, #[[2]] === ConditionalExpression[1, 1 <= t <= 5] &]


So the main reason why it did not find the third entry before, is that under the cover t >= 1 && t <= 5 is not the same as 1 <= t <= 5