search

Home  >  Q&A  >  body text

Will selecting specific columns affect the number of rows in MySQL?

I have a simple query with a few joins, but when I add columns to my selection from the same set of joins, just adding or removing columns from the selection without changing any of the joins, the number of rows There will be changes.

P粉964682904P粉964682904263 days ago363

reply all(1)I'll reply

  • P粉250422045

    P粉2504220452024-03-30 13:16:39

    Yes, they can. For example, your query, or "simple query" as you call it, can have different keywords, and adding a column to a similar select will change the total number of rows in the results.

    select distinct t1.id, t2.id
    from t1
    left join t2 on t1.id = t2.id

    VS

    select distinct t1.id, t2.id, t2.job
    from t1
    left join t2 on t1.id = t2.id

    This is a demo

    reply
    0
  • Cancelreply