I need some help with MySQL query. Hope someone can help me 'cause Im having a hard time.
Here's my query so far:
"SELECT *
FROM `users`
JOIN `m_table1` ON users.user_id = m_table1.user_id
JOIN `m_table2` ON users.user_id = m_table2.user_id
JOIN `m_table3` ON users.user_id = m_table3.user_id
WHERE users.user_id=3"
I want to add month and year on WHERE clause, but month and year column can be found on tables m_table1, m_table2, m_table3.
Thanks!
Here is a visual, tweak any which way. Uses table aliases too for less typing:
SELECT u.*
FROM `users` u
JOIN `m_table1` t1 ON u.user_id = t1.user_id
JOIN `m_table2` t2 ON u.user_id = t2.user_id and t2.year=1942
JOIN `m_table3` t3 ON u.user_id = t3.user_id and t3.year=1942 and t3.month=7
WHERE u.user_id=3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With