Is it possible to write a MySQL query to find a chain of friends in a relational database?

Practice




Is it possible to write a MySQL query to find a chain of friends? on a relational database?

using one of the algorithms
Floyd-Warshall algorithm
Dijkstra's algorithm
Bidirectional search. D


so here's the problem
there's a table with roughly this structure

ID IDUSER1 IDUSER2


if such a connection exists, then they are friends

need to get the shortest chain of friends between two people (if one exists), with output of all intermediate friends
created: 2013-08-06
updated: 2026-03-09
468



Was this answer useful?
Choose a quick rating so we can improve the next answer for you.
How satisfied are you?


Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Databases - MySql (Maria DB)"

Terms: Databases - MySql (Maria DB)