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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:12:12+00:00 2026-06-03T14:12:12+00:00

A simple quiz: Probably many guys know this before, In my app there is

  • 0

A simple quiz:

Probably many guys know this before,

In my app there is a query in which Im using concat in where condition like this,

v_book_id and v_genre_id are 2 variables in my procedure.

SELECT link_id 
FROM link
WHERE concat(book_id,genre_id) = concat(v_book_id,v_genre_id);

Now, I know there is a catch/bug in this, which will occur only twice in your lifetime. Can you tell me what is it?

I found this out yesterday and thought I should make a noise about all others practicing this.

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-03T14:12:15+00:00Added an answer on June 3, 2026 at 2:12 pm

    Let’s have a look

    WHERE concat(book_id,genre_id) = concat(v_book_id,v_genre_id);
    

    as opposed to

    WHERE book_id = v_book_id AND genre_id = v_genre_id;
    

    There. The second solution is

    • faster (optimal index usage)
    • easier to write (less code)
    • easier to read (what on earth was the author thinking to concatenate numbers???)
    • more correct (as Alnitak also stated in the question’s comments). check out this sample data:

      book_id | genre_id
      1       | 12
      11      |  2
      

      Now add (or concat) v_book_id = 1 and v_genre_id = 12 and see how you’ll get funny results with your concat() query

    Note, some databases (including MySQL) allow operations on tuples, which may be what the clever author of the above really intended to do:

    WHERE (book_id, genre_id) = (v_book_id, v_genre_id);
    

    A working example of such a tuple predicate:

    SELECT * FROM (
      SELECT 1 x, 2 y FROM DUAL UNION ALL
      SELECT 1 x, 3 y FROM DUAL UNION ALL
      SELECT 1 x, 2 y FROM DUAL 
    ) a
    WHERE (x, y) = (1, 2)
    

    Note, some databases will need extra parentheses around the right-hand side tuple : ((1, 2))

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

Sidebar

Related Questions

Simple query, possibly impossible but I know there are some clever people out there
Simple (probably stupid) question. I'm a Powershell novice and am mainly using it to
All applicants to our company must pass a simple quiz using C as part
I've developed a Flash quiz app for facebook, which calls for a php script
I am trying to implement a simple quiz app on the iphone in the
I'm trying to create a simple Quiz app (I'm a beginner), when I launch
I'm making a simple quiz application which has multiple questions. It has no back
I'm going to make simple quiz form on site. Are there ways to make
I'm developing a simple web quiz and using javascript, I would like to create
Simple question, is it possible to achieve this query this with Entity Framework when

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.