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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:22:06+00:00 2026-05-16T14:22:06+00:00

My query is this SELECT C.id, C.title, C.short_description,C.rating,C.image,C.duration,C.difficulty , 0 AS active , if(G.theme_id

  • 0

My query is this

SELECT C.id, C.title, C.short_description,C.rating,C.image,C.duration,C.difficulty ,  
0 AS active , if(G.theme_id = 3,1,0) as orderField
FROM tblIdeas C
INNER JOIN tblIdeas_themes G on (G.Idea_id = C.id )
AND C.category_id = 2  and C.published = 1 and C.DELETED=0 and C.id != 4 
ORDER BY active DESC , orderField DESC ,title ASC

 tblideas ------ id,description , etc
    tblideas_themes    -------- idea_id , theme_id
    tblthemes -------------id , theme_name

in tblideas_themes i have one idea with multiple themes.

I want that if idea belong to particular theme then order field should be one and if not the orderfield should be 0

The problem is i am getting duplicate rows e,g

Idea 1 ---------- with orderField 1 --as it was in that theme
Idea 1 -----------with order field 0 as ---it was also in the other theme as well

I want that there should be only one idea in the list.

If the idea belongs to more than one theme then i want get that row which belongs to that theme with orderfield =1 . but if idea does not belong to that theme , then i want to get any other row with orderfield = 0

  • 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-16T14:22:07+00:00Added an answer on May 16, 2026 at 2:22 pm

    You can reduce the rows to one row per idea with GROUP BY.

    Use an OUTER JOIN to join to the themes table, and add the theme_id=3 condition to the join expression. So if a theme with theme_id=3 is found, the orderField will be 1. If no theme with theme_id=3 is found, then it’ll be null because of the outer join, and orderField will default to 0.

    SELECT C.id, C.title, C.short_description, C.rating, C.image, C.duration, 
        C.difficulty, 0 AS active, IF(G.theme_id = 3,1,0) as orderField
    FROM tblIdeas C
    LEFT OUTER JOIN tblIdeas_themes G ON (G.Idea_id = C.id AND G.theme_id = 3)
    WHERE C.category_id = 2  and C.published = 1 and C.DELETED=0 and C.id != 4 
    GROUP BY C.id
    ORDER BY active DESC , orderField DESC ,title ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query: SELECT page.id, revision.title, revision.number FROM page INNER JOIN revision ON
I currently have this query set-up: SELECT topic.content_id, topic.title, image.location FROM mps_contents AS topic
I currently have this query set-up: SELECT topic.content_id, topic.title, image.location FROM mps_contents AS topic
The original query looks like this (MySQL): SELECT * FROM books WHERE title LIKE
How could I take a mysql query like this: SELECT id,title,timestamp,upvotes,downvotes,views FROM {$table} ORDER
Ok, this is my query: SELECT video_category, video_url, video_date, video_title, short_description, MAX(video_id) FROM videos
I have a query something like this: SELECT title, desc, date FROM tablename ORDER
When i write this query SELECT cd.title, cd.city FROM coupon_detail cd WHERE cd.id =
I have this sql query: SELECT S.SEARCH, S.STATUS, C.TITLE AS CategoryName, E.SEARCH_ENGINES AS Engine,
i got this SQL query where post_title taken from $_GET $sql = SELECT 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.