I have two tables, posts and pages. The posts table has more columns than the pages table, but other than that they are the same in terms of schema.
If a slug is given, the row with the right slug could exist in the pages table, or the posts table. I was thinking of something like
SELECT *
FROM pages
WHERE slug = 'about'
UNION
SELECT *
FROM posts
WHERE slug = 'about'
but that requires the row with the slug of “about” to be in both tables. There’s probably a simple INNER JOIN I could use, but my SQL knowledge is limited.
To clarify, I want to be able to search across both tables as if they were one.
Here is the posts table structure:
`slug` varchar(128) NOT NULL,
`id` varchar(100) NOT NULL,
`title` text NOT NULL,
`published` bigint(20) NOT NULL,
`content` longtext NOT NULL,
`author` text NOT NULL,
`status` enum('published','draft','trashed') NOT NULL
and the pages structure:
`slug` varchar(128) NOT NULL,
`id` varchar(100) NOT NULL,
`title` text NOT NULL,
`content` longtext NOT NULL,
`menu_order` int(11) DEFAULT NULL,
`status` enum('published','drafted','trashed') NOT NULL
You can use union but you need to specify columns (col1,col2,..) the two list should be identical: