There was a table by the window. / There was a table next to the window.
They live by the lake. / They live next to the lake.
When should you use by and when next to? Why?
Both the OP's examples with table and window are acceptable and common, they have very very similar meanings
There was a table by the window
There was a table next to the window
I wouldn't know which one to choose, perhaps by has a more formal feel.
5. Indicating location of a physical object beside a place or object.
- ‘remains were discovered by the roadside’
- ‘the pram was by the dresser’
next to, beside, next door to, alongside, at the side of, by the side of, abreast of, adjacent to, cheek by jowl with, side by side with
near, close to, hard by, nearest to, neighbouring, adjoining, abutting, bordering, overlooking
However, just the other day I was making flashcards for a group of private students, and in one of the cards there was a picture of a couple having a romantic picnic very close to the lake.
I could have written “Romantic picnic next to the lake”
Instead, without thinking twice, I labelled it:
Romantic picnic by the lake
If the picture had shown a building e.g., a bungalow, in the vicinity of the sea, I'd have probably said
A bungalow facing the sea
A bungalow in front of the sea
A bungalow near the sea
But not “a bungalow next to the sea”
When something is “by” a place, it can be in any position, it is not necessarily beside or opposite that area.
For me, “by” feels closer than “near” but slightly further than next to.
When I Ngrammed “picnic by the river/lake/sea”, the following results were yielded. People seem to picnic by the river six times more frequently than by the sea. (I hope I interpreted that statistic correctly, I'm not good at numbers I'm afraid).
A lake doesn't normally have "sides" while a river can have two sides. You can only have a picnic on one side of the sea, the one facing it, so maybe that explains, in part, the discrepancy between the results.
However, when I used Google Ngram to chart the following expressions “picnic next to the river/lake/sea”, it turned up blank and said: *No valid ngrams to plot! Ngrams not found: picnic next to the river, picnic next to the lake, picnic next to the sea.
Which suggests that English speaking people do not use "picnic" in conjunction with "next to" if the location is a large undefined body of water. What happens if the body of water has straight lines or a definite shape? According to Google Books, there are some instances of next to the pool but compared to by the pool the latter form is by far preferred.