I am looking to write a query that outputs the columns of two tables. I was looking to do a join maybe but if I join on either the left or right tables, a value might not be returned. I thought of using the UNION keyword but it renames the columns to one name. Then I do not know which column has what.
I want my query to select the columns in both tables, but not care if a match for username exists in either table, or neither. I just want all the columns that don't have values to be there anyway.
SELECT *
FROM client_table
JOIN staff_table
ON client_table.username = staff_table.username
WHERE client_table.username = " . mysql_real_escape_string($gotMyUser) . "
OR staff_table " . mysql_real_escape_string($gotMyUser) . " LIMIT 1
UPDATE:
here is the output of the query
Array
(
//FIRST TABLE
[client_id] => 332058
[username] => jake
[firstname] => jake
[lastname] => ****
[email] => *****
[phone] =>
[phone_ext] =>
[mobile] =>
[department] =>
[is_active] => 1
[default_site] => 0
[google] =>
//SECOND TABLE
[staff_id] =>
[group_id] =>
[dept_id] =>
[passwd] =>
[signature] =>
[isactive] =>
[isadmin] =>
[isvisible] =>
[onvacation] =>
[daylight_saving] =>
[append_signature] =>
[change_passwd] =>
[timezone_offset] =>
[max_page_size] =>
[auto_refresh_rate] =>
[created] =>
[lastlogin] =>
[updated] =>
)
This is exactly what i want because i want to know if the user either has a staff id or a client id but depending on which join (LEFT RIGHT or FULL) i do it may not return any results. I wish for the result to contain all of these columns everytime i execute the query and then i test:
if($array['client_id']){
//do stuff with client
}
else if($array['staff_id']){
//do stuff with staff
}