1

I want to access a database merging two tables from a php script in order to output the result to an html table. Both tables are pretty much the same except one column I need only exists in one table. I don't have direct access to the database.

INSERT INTO globalusers
(surname, firstname, email, location)

INSERT INTO localusers
(surname, firstname, email)

Location exists only in globalusers. I need to use this column as a dropdown filter in my table and add the column location with the string "local" to the data coming from the localusers table.

Here's a fiddle

So the expected result would be one table with four columns and the string "local" in the location column for the localusers table.

What is the select that I need?

MySQL version: 5.5.36

1 Answer 1

4

Sounds like you're looking to combine the results of the two tables. If so, you can use UNION ALL for this:

SELECT surname, firstname, email, location
FROM globalusers
UNION ALL
SELECT surname, firstname, email, 'local'
FROM localusers
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.