user1187
user1187

Reputation: 2218

How to write a query for fetching from two table in a single field

I have two tables

one table is for storing video course details and the other table is for storing audio course details

here is the table create structure

for audio

CREATE TABLE IF NOT EXISTS `audio_master` (
  `audio_id` int(11) NOT NULL AUTO_INCREMENT,
  `audio_title` varchar(255) DEFAULT NULL,
  `course_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`audio_id`)
) 



INSERT INTO `audio_master` (`audio_id`, `audio_title`, `course_id`) VALUES
(1, 'java audio', 1),
(1, 'java audio2', 1); 

for video

 CREATE TABLE IF NOT EXISTS `video_master` (
      `video_id` int(11) NOT NULL AUTO_INCREMENT,
      `video_title` varchar(255) DEFAULT NULL,
      `course_id` int(11) DEFAULT NULL,
      PRIMARY KEY (`video_id`)
    ) 

INSERT INTO `video_master` (`video_id`, `video_title`, `course_id`) VALUES
    (1, 'java video', 1),
    (1, 'java video2', 1); 

I have to show one audio and one video simultaneously in the following way

Course Materials

java video
java Audio
java Video1
java Audio1 

How to write a query for fetching this way

Thanks in advance

Upvotes: 0

Views: 44

Answers (1)

Dan Saunders
Dan Saunders

Reputation: 280

Assuming the data in the 2 tables is not related (you are not expecting it to be joined together but just need to create one list from both tables) it is as simple as:

SELECT video_title FROM video_master
UNION ALL
SELECT audio_title FROM audio_master

Upvotes: 3

Related Questions