Can selected columns change the number of rows in MySQL?

223 Views Asked by At

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.

1

There are 1 best solutions below

2
VBoka On BEST ANSWER

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