robs99 Posted March 3, 2009 Share Posted March 3, 2009 hey, ive got problem. im trying to kind of combine 2 tables in one query. ive searched and tried to look at examples but i didnt get it to work lets say i have 2 tables. one with posts which looks like this: posts: post_id, content, author and one which saves the post-id of a flagged post and the user-id of the user who flagged it flags: post_id, user_id what i want to do is show whether a post has been flagged or not in one query. lets say display the output like this: post_id, content, author, flagged (flagged can be true or false) is there a way to do is? sorry for sounding so confusing ive tried to find a solutions for the past 3 hours and my head is about to burst... Link to comment https://forums.phpfreaks.com/topic/147706-select-values-from-2-tables-with-1-query/ Share on other sites More sharing options...
HuggieBear Posted March 3, 2009 Share Posted March 3, 2009 Have you tried using SQL JOINS? Link to comment https://forums.phpfreaks.com/topic/147706-select-values-from-2-tables-with-1-query/#findComment-775325 Share on other sites More sharing options...
HuggieBear Posted March 3, 2009 Share Posted March 3, 2009 I expect something like this is going to give you what you're after SELECT p.post_id, p.content, p.author, f.user_id FROM posts p LEFT JOIN flags f ON p.post_id = f.post_id Link to comment https://forums.phpfreaks.com/topic/147706-select-values-from-2-tables-with-1-query/#findComment-775334 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.