Home > database >  Can selected columns change the number of rows in MySQL?
Can selected columns change the number of rows in MySQL?

Time:05-25

I have a simple query with a couple of joins but when I add columns in to my selection from the same set of joins, number of rows change by just adding or removing columns in selection without changing any joins.

CodePudding user response:

Yes they can. Your query or as you call it "simple query" can have, for example, keyword distinct and adding a column to a select like that will change the number of total rows in your result.

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

Here is a demo

  • Related