How can I join two tables together in drupal 7.
I have a simple database schema and I want to join it to the user table could someone give me a coded example of joining a custom build table to the user table.
If I take a basic table example
$schema['location'] = array (
'descritiption' => 'location',
'fields' => array (
'locationID' => array(
'description' => 'primary key for patients table',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE),
),
'addressone' => array (
'description' => 'this shows the first line of the address',
'type' => 'TEXT'
),
'county' => array (
'description' => 'this is a county list'
),
'postcode' => array (
'deescription' => 'stores the postcode'
),
'primary_key' => array('locationID')
);
How would I join this to the user table. I would like to query data from both tables. So when I add a record into the user table I want the custom table to have the data added as well so there is a link between the two tables.
here is a high level example
user table data
uid 1
username alex
visitor
vis id 1
firstname Alexander
lastname Brown
So what i want to happen is when i add data into the user table I build a relationship to what is entered in the visitors table. I know you can use a join which has kindly been explained to me but I am not sure what is meant by building the relationships in code.