Retrieving all values โโfrom three different tables. JOIN task?
I am learning mysql and trying to get this to work, but the error always comes up no matter how I try it, or it just shows nothing from the table.
I have 3 tables, all with the same number of columns and column name
I want to list all values โโin alphabetical order by name
Tables: General - Temp - Location
Columns: id - url - title - description
How would you write a select statement?
I've tried many ways and can't figure it out ... I guess it will look like
SELECT * FROM General JOIN Temp ON General.title = Temp.title JOIN Location ON Temp.title = General.title
I have been actively playing around with changing values โโlike Temp.title = General.title and doesn't seem to help
Any ideas?
Thank!
ps - I also tried this and it gives data but only shows a few results from the total table with the number of messages from temp .. very confusing
SELECT
General.id,
General.url,
General.title,
General.description,
Temp.id,
Temp.url,
Temp.title,
Temp.description,
Location.id,
Location.url,
Location.title,
Location.description
FROM
General INNER JOIN Temp
ON General.id = Temp.id
INNER JOIN Location
ON Temp.id = Location.id
ORDER BY
General.title
source to share
To add a table with an extra column:
SELECT NULL 'id',
NULL 'url',
NULL 'title',
NULL 'description',
NULL 'extra_column'
FROM DUAL
UNION
SELECT g.id,
g.url,
g.title,
g.description,
NULL
FROM GENERAL g
UNION
SELECT t.id,
t.url,
t.title,
t.description,
NULL
FROM TEMP t
UNION
SELECT l.id,
l.url,
l.title,
l.description,
NULL
FROM LOCATION l
ORDER BY title
This assumes that you want all columns from the additional table. If you don't, do not include the extra column, but make sure the data types match the position in the SELECT statement.
source to share