Joining two tables in one has a subquery which is returning id count present in one table which is not presented on another field of a particular user I have a two tables 

My first table goes in at this way 

CREATE TABLE `inventory` (
  `id` int(64) NOT NULL,
  `user_id` int(50) NOT NULL,
  `placed_date` date NOT NULL,
  `name_of_campaign` varchar(250) NOT NULL,
  `budget` int(64) NOT NULL,
  `start_date` date NOT NULL,
  `ending_date` date NOT NULL,
  `platformType` int(64) NOT NULL,
  `titleOfTheVideo` varchar(250) NOT NULL,
  `videoUrl` varchar(250) NOT NULL,
  `redirection_url` varchar(250) NOT NULL,
  `photo_url` varchar(250) NOT NULL,
  `tags` varchar(250) NOT NULL,
  `language` int(64) NOT NULL,
  `country` int(11) DEFAULT NULL,
  `state` int(11) NOT NULL,
  `city` int(11) NOT NULL,
  `age` int(64) NOT NULL,
  `max_age` int(11) NOT NULL,
  `gender` int(64) NOT NULL,
  `publisher_catagory` int(64) NOT NULL,
  `publisher_name` int(64) NOT NULL,
  `status` int(11) NOT NULL,
  `paid` int(60) NOT NULL,
  `min_cpc` int(60) NOT NULL,
  `max_cpc` int(60) NOT NULL,
  `min_cpv` int(60) NOT NULL,
  `max_cpv` int(60) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


For this data 

INSERT INTO `inventory` (`id`, `user_id`, `placed_date`, `name_of_campaign`, `budget`, `start_date`, `ending_date`, `platformType`, `titleOfTheVideo`, `videoUrl`, `redirection_url`, `photo_url`, `tags`, `language`, `country`, `state`, `city`, `age`, `max_age`, `gender`, `publisher_catagory`, `publisher_name`, `status`, `paid`, `min_cpc`, `max_cpc`, `min_cpv`, `max_cpv`) VALUES
(49, 113, '2018-05-02', 'Ads', 50000, '2018-05-25', '2018-05-28', 1, 'Some title', 'uploadvideos/arun vm.webm', 'http', 'screenimages/arun vm.png', 'videoads,videos,ads', 2, 96, 1639, 1103581, 25, 30, 2, 1, 109, 1, 1, 25, 30, 5, 10);


And my second table.

CREATE TABLE `ad_analytics` (
  `id` int(90) NOT NULL,
  `ad_id` int(90) NOT NULL,
  `advertiser_id` int(90) NOT NULL,
  `publisher_id` int(90) NOT NULL,
  `visitor_ip` varchar(250) NOT NULL,
  `type_ad` varchar(90) NOT NULL,
  `impression` int(90) NOT NULL,
  `view` int(90) NOT NULL,
  `clicks` int(90) NOT NULL,
  `date_event` date NOT NULL,
  `placed_date` date NOT NULL,
  `ending_date` date NOT NULL,
  `cpc` int(60) NOT NULL,
  `cpv` int(60) NOT NULL,
  `cpi` int(60) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


Data for the same.

INSERT INTO `ad_analytics` (`id`, `ad_id`, `advertiser_id`, `publisher_id`, `visitor_ip`, `type_ad`, `impression`, `view`, `clicks`, `date_event`, `placed_date`, `ending_date`, `cpc`, `cpv`, `cpi`) VALUES
    (1, 49, 113, 109, '::1', 'Video', 1, 0, 0, '2018-05-01', '2018-05-01', '2018-05-01', 0, 0, 0),
    (2, 49, 113, 109, '::1', 'Video', 0, 0, 1, '2018-05-01', '2018-05-01', '2018-05-01', 3, 0, 0),
    (3, 49, 113, 109, '::1', 'Video', 1, 0, 0, '2018-05-01', '2018-05-01', '2018-05-01', 0, 0, 0),
    (4, 49, 113, 109, '::1', 'Video', 0, 0, 1, '2018-05-01', '2018-05-01', '2018-05-01', 3, 0, 0),
    (5, 49, 113, 109, '::2', 'Video', 1, 0, 0, '2018-05-01', '2018-05-01', '2018-05-01', 0, 0, 0),
    (6, 49, 113, 109, '::2', 'Video', 0, 0, 1, '2018-05-01', '2018-05-01', '2018-05-01', 3, 0, 0),
    (7, 49, 113, 109, '::2', 'Video', 1, 0, 0, '2018-05-01', '2018-05-01', '2018-05-01', 0, 0, 0),
    (8, 49, 113, 109, '::2', 'Video', 0, 0, 1, '2018-05-01', '2018-05-01', '2018-05-01', 3, 0, 0),
(7, 49, 113, 109, '::2', 'Video', 1, 0, 0, '2018-05-01', '2018-05-01', '2018-05-01', 0, 0, 0),
    (8, 49, 113, 109, '::2', 'Video', 0, 0, 1, '2018-05-01', '2018-05-01', '2018-05-01', 3, 0, 0);


This query

select id,
  ad_id,
  sum(impression) total_impression,
  sum(view) total_views,
  sum(clicks) total_clicks,
  publisher_id
from
  (select id,
     ad_id,
     max(impression)  impression,
     max(view)  view,
     max(clicks)  clicks,
     visitor_ip,
     publisher_id
  from ad_analytics
  group by ad_id, visitor_ip) t group by t.ad_id;


In at the second table gives me this answer.



Now i want to fetch this answer along with the ad name and budget from my first table i am not getting a proper way to join the tables how can i do the same?
As far as I understand, a simple inner join on the foreign key/primary key pair should suffice?

Assuming that ad_analytics.ad_id refers to inventory.id (consider using foreign key constraints!) and by "name" you mean name_of_campaign I have something like

select t.id,
  t.ad_id,
  sum(t.impression) total_impression,
  sum(t.view) total_views,
  sum(t.clicks) total_clicks,
  t.publisher_id,
  i.budget,
  i.name_of_campaign
from
  (select id,
     ad_id,
     max(impression)  impression,
     max(view)  view,
     max(clicks)  clicks,
     visitor_ip,
     publisher_id
  from ad_analytics
  group by ad_id, visitor_ip) t
  inner join inventory i
             on i.id = t.ad_id
group by t.ad_id;


in mind.

Note, that I had to introduce using the aliases as a prefix in the list of selected columns, as id would have been ambiguous otherwise (it's in both tables).