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 6585195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:37:53+00:00 2026-05-25T16:37:53+00:00

I have a problem with comparing a string to integer columns of different tables

  • 0

I have a problem with comparing a string to integer columns of different tables in database.

Have a database with two tables as categories and content. Now each content text can belong to more than one category which is listed in category_ids column of content table separated by comma. I know it is not normalized. But it is already there.

categories table

id | name | timestamp
 1   aaa    something
 2   bbb    something
 3   ccc    something
 4   ddd    something
 5   eee    something

content table

id | category_ids | content | timestamp
 1     1              xxx     something
 2     1,2,3,4        yyy     something
 3     1,2            zzz     something
 4     1,2,3          www     something

Now i have to show list of categories with the count of content text in each categories.
Means number of content text using that category in it. Note (category eee is not there in any content text so showing 0 count in result set.)

aaa(4)
bbb(3)
ccc(2)
ddd(1)
eee(0)

i tried alot of ways to compare id of categories table to category_ids of content table. But one is integer and other one is string.

one way i tried is cast function but failed

SELECT C.id , C.Name, COUNT( * ) AS ContentCount FROM categories AS C LEFT JOIN content  AS Q ON (CAST(C.id AS CHAR) = (Q.category_ids))  GROUP BY C.Name

Please dont tell me ways to change the database. If any ideas that how can i write a query which will give me this kind of result set will be highly appreciated.

  • 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-05-25T16:37:54+00:00Added an answer on May 25, 2026 at 4:37 pm

    CSV in a database is the worst idea ever.
    It will kill any chance of using an index. It’s not normalized. It’s slow.
    It will keep on biting you again and again.

    SELECT C.id , C.Name, COUNT( * ) AS QuotesCount 
    FROM categories AS C 
    LEFT JOIN quotes  AS Q ON (FIND_IN_SET(c.id,Q.category_ids))
    GROUP BY C.Name
    

    See: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_find-in-set

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

Sidebar

Related Questions

Hey I have a problem comparing the value of a CGPoint (struct with two
I have a problem with comparing two arraylist, my first arraylist looks like this:
I have problem when I try insert some data to Informix TEXT column via
I have this function that converts an integer to a std::string: std::string intToStr(const int
I have a problem that consist in comparing boolean expressions ( OR is +,
I have an android app. in that I am comparing two strings from the
We have three tables to hold our products and keywords: Product {int ID, string
I am having an issue with comparing text input with the values I have
I have two strings both with value null . But when I am comparing
I have a problem with compiling an Oracle trigger via SQL*PLUS - I don't

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.