HoTDaWg Posted August 20, 2009 Share Posted August 20, 2009 hi there, heres the code im using for my inner join <?php $query = "SELECT * FROM blog_history INNER JOIN blog_links" . " USING(history_shared == link_id) WHERE blog_history.history_type='3'" . " LIMIT $skip,$results_per_page ORDER BY blog_history.history_id DESC"; ?> here is the structure for these two tables: blog_history CREATE TABLE IF NOT EXISTS `blog_history` ( `history_id` int(50) NOT NULL AUTO_INCREMENT, `history_type` varchar(250) DEFAULT NULL, `history_date` varchar(250) DEFAULT NULL, `history_shared` varchar(250) DEFAULT NULL, PRIMARY KEY (`history_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ; blog_links CREATE TABLE IF NOT EXISTS `blog_links` ( `link_id` int(50) NOT NULL AUTO_INCREMENT, `link_type` varchar(50) DEFAULT NULL, `link_title` varchar(500) DEFAULT NULL, `link_link` varchar(7000) DEFAULT NULL, `link_description` varchar(1500) DEFAULT NULL, `link_date` varchar(100) DEFAULT NULL, PRIMARY KEY (`link_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; any ideas where i went wrong in the query structure guys? any help would be greatly appreciated, thanks, HoTDaWg Quote Link to comment https://forums.phpfreaks.com/topic/171101-need-help-with-inner-join/ Share on other sites More sharing options...
Psycho Posted August 20, 2009 Share Posted August 20, 2009 Not sure what you are trying to do with the USING() clause, but your usage is incorrect. That clause is supposed to specify multiple columsn - separated by commas - which exist in both tables. Records will be matched where the values of those columns are equal. Quote Link to comment https://forums.phpfreaks.com/topic/171101-need-help-with-inner-join/#findComment-902313 Share on other sites More sharing options...
phpdeveloper82 Posted August 20, 2009 Share Posted August 20, 2009 You can easily join the two tables like this: blog_history INNER JOIN blog_links" SELECT history.column_name1, history.column_name2, links.column_name1, links.column_name2 FROM blog_history as history, blog_links as links WHERE history.id=links.id On both tables (history & links), there is a common field to join them. Hope this will helps you...... Quote Link to comment https://forums.phpfreaks.com/topic/171101-need-help-with-inner-join/#findComment-902365 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.