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.");
SELECT * 
FROM   property, 
       personal,
       spouse
WHERE property.id=personal.id
AND   property.id=spouse.id

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:

thanks a lot!it's now working :)

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.