Join tables

hey guys,

i currently have the following code:

(SELECT ud.user_id, ud.username, us.post_body, us.date_posted, ui.name, ui.date_uploaded
FROM user_friends AS uf
CROSS JOIN user_details AS ud ON ud.user_id = uf.user_id_link2
LEFT OUTER JOIN user_statuses AS us ON us.user_id = uf.user_id_link2
LEFT OUTER JOIN user_images AS ui ON ui.user_id = uf.user_id_link2                    
WHERE uf.user_id_link1 = '$loggedInUserId')
UNION ALL
(SELECT ud.user_id, ud.username, us.post_body, us.date_posted, ui.name, ui.date_uploaded
FROM user_friends AS uf
CROSS JOIN user_details AS ud ON ud.user_id = uf.user_id_link1
LEFT OUTER JOIN user_statuses AS us ON us.user_id = uf.user_id_link1
LEFT OUTER JOIN user_images AS ui ON ui.user_id = uf.user_id_link1
WHERE uf.user_id_link2 = '$loggedInUserId')

which uses a bi-directional table called “user_friends” to gather the friends of the logged in user ($loggedInUserId)
it then uses CROSS JOIN to gather details for each friend from “user_details”
then looks for status updates (user_statuses), and image uploads (user_images) by that friend, for each friend

…my problem is that this currently returns rows containing both status updates and image uploads, but i need a row per status update for each friend and a row per image upload for each friend

then i need it to sort each status and image upload by “us.date_posted” and “ui.date_uploaded”

i need this as im trying to make a “Friend’s Updates” section on my site, showing a combination of status message updates and image uploads for each friend by most recent first

thanks for reading, and any help (:

general table structures, if needed:

--
-- Table structure for table `user_details`
--
CREATE TABLE IF NOT EXISTS `user_details` (
  `user_id` varchar(20) NOT NULL,
  `username` varchar(25) NOT NULL,
  PRIMARY KEY (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


--
-- Table structure for table `user_friends`
--
CREATE TABLE IF NOT EXISTS `user_friends` (
  `id` int(20) NOT NULL AUTO_INCREMENT,
  `user_id_link1` varchar(20) NOT NULL,
  `user_id_link2` varchar(20) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `user_id_link1` (`user_id_link1`,`user_id_link2`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=40 ;


--
-- Table structure for table `user_images`
--
CREATE TABLE IF NOT EXISTS `user_images` (
  `id` int(20) NOT NULL AUTO_INCREMENT,
  `user_id` varchar(20) NOT NULL,
  `date_uploaded` int(10) NOT NULL,
  `name` varchar(32) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=155 ;


--
-- Table structure for table `user_statuses`
--
CREATE TABLE IF NOT EXISTS `user_statuses` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` varchar(20) NOT NULL,
  `post_body` text,
  `date_posted` int(10) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;

I apologize I won’t be able to help but I just realized something. It is hard to expect someone to answer when you form your queries in a not very attractive way. It would take me around 10 minutes just to get a very vague idea of what is going on. Sorry.