1

Wanna fetch data from 3 tables by mysql query to display in feed. But stack. My query is

SELECT f.leaderId, f.followerId, c.ccId, c.ccTitle, c.ccCity, c.ccCountry, c.ccFlag, c.uId, c.ccStartingDate, c.ccCreatedAt, l.uId, l.ccId
FROM followingrelations f, conferencecreate c, likesbyuser l
WHERE f.followerId = 'login_user_id'
      AND c.uId = f.leaderId
      AND c.ccFlag = 1
      AND c.ccStartingDate >= 'current_time_and_date_now' 
      OR l.uId = f.leaderId
GROUP BY c.ccTitle 
ORDER BY c.ccId DESC;

Expectation:

  1. Want to fetch data where uId and leaderId are matched from followingrelations and conferencecreate tables respectively.

  2. Beside above condition, want to fetch data also if any user likes any post. The condition I putted like this way OR l.uId = f.leaderId

Am I on right track?

I implemented this query but nothing displaying. Any idea how to solve this issue plz?

My database design is in following:

enter image description here

3
  • Can you explain again your expectations ? I absolutely don't get what you want. Also, in your query, you may want to use SELECT ... FROM table1 INNER JOIN table2 ON table1.id = table2.id INNER JOIN table 3 ON table1.id = table3.id WHERE ... in order to clarify your query because it's impossible to understand what your different WHERE-clauses do (joining or filtering ?)
    – Eric Ly
    Jan 21, 2016 at 18:24
  • Actually, I want to make a feed page based on my data in above tables. More specifically feed page like facebook where will get friends update status and on what they like / comments. Just want to make this. Any idea?
    – tisuchi
    Jan 22, 2016 at 13:58
  • Dont join tables like that: "FROM followingrelations f, conferencecreate c, likesbyuser l" It produces a CROSS JOIN and you need to provide JOIN predicates in a WHERE clause. This style used to be popular like 15 years ago. It is a really bad practice, It's hard to read and even harder to debug.
    – BuahahaXD
    Feb 11, 2016 at 10:35

1 Answer 1

1

Please try it.

SELECT f.leaderId, f.followerId, c.ccId, c.ccTitle, c.ccCity, c.ccCountry, c.ccFlag, c.uId, c.ccStartingDate, c.ccCreatedAt, l.uId, l.ccId
        FROM  conferencecreate c
left join followingrelations f on c.uId = f.leaderId
left join likesbyuser l on  (c.ccStartingDate >= 'current_time_and_date_now' or l.uId = f.leaderId )
        WHERE f.followerId = 'login_user_id'
        AND c.ccFlag = 1
        GROUP BY c.ccTitle 
        ORDER BY c.ccId DESC

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.