Friday, 22 January 2021

How to get data from following and follower in mysql

 

 

Query 1
SELECT
  `connection`.`person_id`,
  `connection`.`follower_id`,
  `people`.`name`,
  `people`.`age`
FROM
  `test`.`people`
  INNER JOIN `test`.`connection`
    ON (
      `people`.`id` = `connection`.`follower_id`
    )
WHERE (`connection`.`person_id` = 3);

Query 2
SELECT person_id, GROUP_CONCAT(DISTINCT follower_id SEPARATOR ', ') AS follower
FROM CONNECTION GROUP BY person_id

Query 3
SELECT person_id, GROUP_CONCAT(DISTINCT follower_id SEPARATOR ', ') AS follower
FROM CONNECTION WHERE (`connection`.`person_id` = 3)
GROUP BY person_id

Query 4
SELECT DISTINCT f.person_id,
o.following,
e.follower
FROM CONNECTION f
LEFT JOIN
(
    SELECT CONNECTION.person_id, GROUP_CONCAT(DISTINCT follower_id SEPARATOR ', ') AS following
    FROM CONNECTION GROUP BY person_id
) AS o ON f.person_id = o.person_id
LEFT JOIN
(
    SELECT CONNECTION.follower_id, GROUP_CONCAT(DISTINCT person_id SEPARATOR ', ') AS follower
    FROM CONNECTION GROUP BY follower_id
) AS e ON f.person_id = e.follower_id

 

2 comments:

Machine Learning - Potato Leaf Disease Prediction

Step 1: import numpy as np import pandas as pd import splitfolders import matplotlib.pyplot as plt import tensorflow as tf from tensorflow i...