Table structure for table `address`
--

CREATE TABLE IF NOT EXISTS `address` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `country` varchar(255) NOT NULL,
  `city` varchar(255) NOT NULL,
  `address` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `address`
--

INSERT INTO `address` (`id`, `user_id`, `country`, `city`, `address`) VALUES
(1, 123, 'philippines', 'makati', 'test address'),
(2, 124, 'philippihiibines', 'oooomakati', 'testibbb address');



Table structure for table `user`
--

CREATE TABLE IF NOT EXISTS `user` (
  `user_id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(254) NOT NULL,
  `password` varchar(254) NOT NULL,
  `firstname` varchar(255) NOT NULL,
  `lastname` varchar(255) NOT NULL,
  `age` int(255) NOT NULL,
  `contactnumber` int(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `country` varchar(255) NOT NULL,
  PRIMARY KEY (`user_id`),
  UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=142 ;

--
-- Dumping data for table `user`
--

INSERT INTO `user` (`user_id`, `username`, `password`, `firstname`, `lastname`, `age`, `contactnumber`, `email`, `country`) VALUES
(139, 'james', 'b4cc344d25a2efe540adbf2678e2304c', 'james', 'james', 22, 12345, ' jamesp', ' Philippines '),
(140, 'john', '527bd5b5d689e2c32ae974c6229ff785', 'john', 'john', 22, 1234, ' john', ' Philippines '),
(141, 'billie', '984fe689d52f9b1259f559975d5fbeb1', 'billie joe', 'posadas', 22, 123456789, ' billiejoeposadas', ' philippines ');


joining tables? help anytime simple only :) or basic! i want to join the id and user_id from address to user mysql thanks

Recommended Answers

All 4 Replies

using php code :)

SELECT * FROM `user`
LEFT JOIN `address` ON `address`.`user_id` = `user`.`user_id`

do i put sql = SELECT * FROM user
LEFT JOIN address ON address.user_id = user.user_id?

No. Use:

$sql = "SELECT * FROM user LEFT JOIN address ON address.user_id = user.user_id";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result))
{
    // use $row['column_name_here']
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.