0
SELECT *, count(idWallHasWallPost) as republish FROM admin_pw.wall_has_wallpost 
    where WallPost_idWallPost in 
    (select WallPost_idWallPost from wall_has_wallpost where Wall_idWall in 
    (select Wall_idWall from follower where User_idUser=1))
    group by WallPost_idWallPost 
    having republish>1;

I have this nested query in mysql. Is there anyway to acces the values from the nested queries higher up in the query.

I would like to access Wall_idWall in last select. I select it the query lowest and would like to see which Wall_idWall was used by the in operator.

2 Answers 2

1

Try:

SELECT w.*, count(w.idWallHasWallPost) as republish, v.all_Wall_idWall
FROM admin_pw.wall_has_wallpost w
join (select h.WallPost_idWallPost, 
             group_concat(distinct h.Wall_idWall) all_Wall_idWall
      from wall_has_wallpost h
      join follower f on h.Wall_idWall = f.Wall_idWall and f.User_idUser=1
      group by h.WallPost_idWallPost) v
on w.WallPost_idWallPost = v.WallPost_idWallPost
group by WallPost_idWallPost 
having republish>1;
Sign up to request clarification or add additional context in comments.

Comments

0

try this if you only need Wall_idWall in last select

SELECT *, count(idWallHasWallPost) as republish,(select Wall_idWall from follower where User_idUser=1) as Wall_idWall FROM admin_pw.wall_has_wallpost 
where WallPost_idWallPost in 
(select WallPost_idWallPost from wall_has_wallpost where Wall_idWall in 
(select Wall_idWall from follower where User_idUser=1))
group by WallPost_idWallPost 
having republish>1;

OR you can change where clause according to your requirements.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.