0

Good day! I have 3 tables name property, personal and spouse, they have all the same id. I want to join the 3 of them, I had already join property and personal table but I can't join the spouse table.

$userquery = mysql_query("SELECT * FROM property, personal WHERE property.id=personal.id") or die ("The query could not be completed.");
3
Contributors
4
Replies
25
Views
2 Years
Discussion Span
Last Post by jorwill.harion
1
SELECT * 
FROM   property, 
       personal,
       spouse
WHERE property.id=personal.id
AND   property.id=spouse.id
1

If the are columns with the same name, for example id, when using the wildcard character the database will return error 1052:

Solution is to define each column:

SELECT property.id, personal.id, spouse.id FROM property JOIN personal ON personal.id = property.id JOIN spouse ON spouse.id = property.id;

As explained in the linked documentation above. Read also:

By the way do not use the MySQL API (mysql_query() & co.) switch to MySQLi or PDO:

Edited by cereal

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.