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

  • Home
  • SEARCH
  • 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 3303680
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:58:56+00:00 2026-05-17T20:58:56+00:00

i have a array of strings i want to write a query such that

  • 0

i have a array of strings i want to write a query such that

  1. first it will count the Id from a particular table say products on the basis of first product names that is in the array

  2. if the value is more than one then select the top one id from the list randomly

  3. otherwise if the count comes one or zero then perform the same query with next value from the string array.

can any body suggest a suitable query for this condition

  • 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-17T20:58:57+00:00Added an answer on May 17, 2026 at 8:58 pm

    I assume that the array data are in TMP_ARRAY.

    You have two sets products and array, You want to retrieve from products only those entires that are in arrays. For this You should use inner join with proper on clause, next you want to set those results in groups GROUP BY by column name, as you want to operate only on those results that single group size is bigger then one, the clause having needs to be added at the end you want to pick from them ‘top’ id. And here we have a problem what You mean by ‘top’? In data base the data don’t have any specific order. I assume that is about the largest, other case in this situation mean only one result, so for both cases we select MAX(ID).

    In result I came up with something like this

    SELECT MAX(ID) FROM PRODUCTS p INNER JOIN TMP_ARRAY t ON t.NAME = p.NAME GROUP BY p.NAME HAVING COUNT(ID) > 1;
    

    But I’m not sure that i have had understand everything correct.

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

Sidebar

Related Questions

I have a string that I want to compare against an array of strings,
I have string that I want to chop to array of substrings of given
Say I have an array of strings in a php array called $foo with
I have a one-dimensional array of strings in JavaScript that I'd like to turn
I have a two-dimensional array (of Strings) which make up my data table (of
Overview: I have an array of 20 byte strings that needs to be stored
I have a table say, ITEM, in MySQL that stores data as follows: ID
During my work with databases I noticed that I write query strings and in
I have a query in linqtosql that returns a LabelNumber: var q = from
I have an array of 1000 strings to load into a combo box. What

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.