`.orderBy` influence `sql` output

With the following code:
  const exchanges = await db
    .select({
      ...getTableColumns(stockExchanges),
      isUsed:
        sql<boolean>`case when ${usedExchanges.data} is not null then 1 else 0 end`.mapWith(
          (value) => value === "1",
        ),
    })
    .from(stockExchanges)
    .leftJoin(usedExchanges, eq(usedExchanges.data, stockExchanges.code));

  console.log(exchanges.find((exch) => exch.code === "BR"));

  const orderedExchanges = await db
    .select({
      ...getTableColumns(stockExchanges),
      isUsed:
        sql<boolean>`case when ${usedExchanges.data} is not null then 1 else 0 end`.mapWith(
          (value) => value === "1",
        ),
    })
    .from(stockExchanges)
    .leftJoin(usedExchanges, eq(usedExchanges.data, stockExchanges.code))
    .orderBy(asc(stockExchanges.name));

  console.log(orderedExchanges.find((exch) => exch.code === "BR"));

I get the following output:
{
  name: 'Euronext Brussels',
  code: 'BR',
  operatingMIC: 'XBRU',
  country: 'Belgium',
  currency: 'EUR',
  countryISO2: 'BE',
  countryISO3: 'BEL',
  isUsed: true
}
{
  name: 'Euronext Brussels',
  code: 'BR',
  operatingMIC: 'XBRU',
  country: 'Belgium',
  currency: 'EUR',
  countryISO2: 'BE',
  countryISO3: 'BEL',
  isUsed: false
}

Why would the orderBy influence the computed column isUsed (the expected result is true)?
Was this page helpful?