Many to many select needed

I have one database with owners, one with property and one with links (relations). Each row in links tell what owner is connected to what property. More than one owner can share one property. But do i make a select of all the property one owner have, and how do i make a select of what owners that share a particular property?

Questions One:  What property's does "Bill" own?
Question Two: Who are the owners of "Red Scorpion"?

-- Definition for database test6534465
--
DROP DATABASE IF EXISTS test6534465;
CREATE DATABASE test6534465
	CHARACTER SET utf8
	COLLATE utf8_general_ci;

-- 
-- Disable foreign keys
-- 
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;

-- 
-- Set SQL mode
-- 
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;

-- 
-- Set default database
--
USE test6534465;

--
-- Definition for table links
--
CREATE TABLE links (
  idLink INT(11) NOT NULL AUTO_INCREMENT,
  idowner INT(11) DEFAULT NULL,
  idproperty INT(11) DEFAULT NULL,
  PRIMARY KEY (idLink)
)
ENGINE = INNODB
AUTO_INCREMENT = 5
AVG_ROW_LENGTH = 4096
CHARACTER SET utf8
COLLATE utf8_general_ci;

--
-- Definition for table owners
--
CREATE TABLE owners (
  idowner INT(11) NOT NULL AUTO_INCREMENT,
  nameowner VARCHAR(50) DEFAULT NULL,
  PRIMARY KEY (idowner)
)
ENGINE = INNODB
AUTO_INCREMENT = 5
AVG_ROW_LENGTH = 4096
CHARACTER SET utf8
COLLATE utf8_general_ci;

--
-- Definition for table property
--
CREATE TABLE property (
  idproperty INT(11) NOT NULL AUTO_INCREMENT,
  propertyname VARCHAR(255) DEFAULT NULL,
  PRIMARY KEY (idproperty)
)
ENGINE = INNODB
AUTO_INCREMENT = 6
AVG_ROW_LENGTH = 3276
CHARACTER SET utf8
COLLATE utf8_general_ci;

-- 
-- Dumping data for table links
--
INSERT INTO links VALUES
(1, 1, 2),
(2, 1, 3),
(3, 2, 2),
(4, 3, 2);

-- 
-- Dumping data for table owners
--
INSERT INTO owners VALUES
(1, 'Bill'),
(2, 'Angus'),
(3, 'Orrin'),
(4, 'Scott');

-- 
-- Dumping data for table property
--
INSERT INTO property VALUES
(1, 'Blue Car'),
(2, 'Red Scorpion'),
(3, 'Green Bicycle'),
(4, 'ThunderBlue'),
(5, 'OldFan');

Open in new window

Paer ToernellAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
looks very like a homework to me? the idea is to join the relevant tables so that you can retrieve the info you needed...
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
To answer your first and second questions, perhaps you can have a consolidated query result, so from this result you can derive to get the results you want....

Select
b.nameowner, c.propertyname
from links a
inner join owners b on a.idowner = b.idowner
inner join property c on a.idproperty = c.idproperty
order by b.nameowner, c.propertyname

Open in new window

Put in the "where" clause into SQL above should manage to resolve your 2 questions
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Paer ToernellAuthor Commented:
Nope, its not homework :) Creating a CRM "ish" system to hold some document together. Have been away from programming 3 years, forgot about joins.  I check Your solution tomorrow. Looks great.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.