Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8093533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:31:22+00:00 2026-06-05T20:31:22+00:00

I have two MySQL tables structed as follows; advert +——————-+————–+ | Field | Type

  • 0

I have two MySQL tables structed as follows;

advert

+-------------------+--------------+
| Field             | Type         |
+-------------------+--------------+
| id                | int(11)      |
| title             | varchar(150) |
+-------------------+--------------+

advert_interest_record

+--------------+------------+
| Field        | Type       |
+--------------+------------+
| id           | int(11)    | 
| advert_id    | int(11)    |
| message      | longtext   |
+--------------+------------+

I want to select a list of all records from the “advert” table – and get the number of rows from the “advert_interest_record” table where advert.id=response.advert_id.

The SQL I’m using to join the tables is as follows;

SELECT advert.id, advert.title 
FROM advert 
LEFT JOIN advert_interest_record ON advert.id = advert_interest_record.advert_id  
GROUP BY advert_interest_record.advert_id 

The first problem I’ve got is that when there are no records in the “advert_interest_record” table, the record from the “advert” table isn’t included in the result – and I need it to be.

My second question is, how would I go about counting the rows in the “advert_interest_record” table?

Any advice on this would be appreciated.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:31:23+00:00Added an answer on June 5, 2026 at 8:31 pm

    First of all; you’re selecting two fields from the advert table; while gouping on one field from the advert_interest_record table.

    Assuming that for all advert.id values, the advert.title value is the same, it might give correct results.

    Anyways; since you want the data in advert to be leading, it’s best to group on the fields of that table that you want uniquely back (which also helps in getting the count of records associated with that in the other table).

    For example, you could query as following:

    SELECT a.id, a.title, COUNT(air.id)
    FROM advert a
    LEFT JOIN advert_interest_records air ON a.id = air.advert_id
    GROUP BY a.id, a.title
    

    This would give you a result of all unique combinations of advert.id and advert.title, together with the number of records in advert_interest_records that are associated with the advert.id value.

    I am assuming that advert.id is unique, and that every id only occurs once. Otherwise the grouping on both id and title (which is not per se needed for MySQL, I believe, in contrast to other DBMS’es), might give you incorrect results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two mysql tables - a sales table: +----------------+------------------------------+------+-----+---------+-------+ | Field | Type
I have the follow two mysql tables: mysql> desc subscriptions; +------------+--------------+------+-----+---------+----------------+ | Field |
I have two mySQL tables as follows: [product] table P_id | Name | Quantity
Ok, I have two MYSQL tables: CREATE TABLE `sessions` ( `id` int(11) NOT NULL
Say I have two tables: mysql> show columns from profiles; +--------------+--------------+------+-----+---------+----------------+ | Field |
I have two MySQL tables: product has id , title , price and some
I have two MySQL tables say A and B. A contains just one varchar
I have two MySql tables like the following: Cat ------ id : INT NOT
I have two MySQL tables, here's how they are structured: table foo( foo_id varchar(32),
I have two MySQL tables something like this: tool_owners: tool_owners_id | user_id | ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.