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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:31:54+00:00 2026-05-26T08:31:54+00:00

i will try to explain the problem. I have this structure: offers ————– id_offer|offer|company

  • 0

i will try to explain the problem.

I have this structure:

offers
--------------
id_offer|offer|company 
1 | web programmer| Microsoft
2 | web programmer| Microsoft


tags
--------------
id_tags | tags
1       | php
2       | js
3       | asp


offers_has_tags
---------------
offers_id_offer (fk) | tags_id_tags (fk)
  1                  | 1
  1                  | 2
  1                  | 3
  2                  | 1
  2                  | 2        

If i use a system like Stackoverflow, where each title of question is unique, there is no problem with the code below. But if i can have various offers with same title, and with same owner, i can’t do WHERE offers = ?,

So, i need a different approach to select a specific job. Can’t be the title, and can’t be the owner+title, because the same owner can have various offers with same title.

  INSERT INTO `offers_has_tags` (
  offers_id_offer,
  tags_id_tags
  ) 
  VALUES (
  (SELECT id_offer FROM offers WHERE offer = ?), //here
  (SELECT id_tags FROM tags WHERE tags = ?))

How can i select an offer when exists more than one, with same title and same owner ?

  • 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-26T08:31:54+00:00Added an answer on May 26, 2026 at 8:31 am

    Simple answer: there is no way to retrieve exactly one row from table if your where clause is not filtering rows by PK columns.

    It is not 100% clear what You are trying to achieve. However, primary key is used to uniquely identify the row. This means that in this case You should use offer_id in where clause (in your insert statement in original question).

    I guess that you have some UI in front of this – why don’t your UI send offer_id to data access code instead of offer name?

    But, if You want to insert all offers with same name and owner to offer_has_tag, try this (it is T-SQL syntax but as far as I can recall it should work on MySQL also):

    INSERT INTO `offers_has_tags` (
      offers_id_offer,
      tags_id_tags
      ) 
    SELECT id_offer, (SELECT id_tags FROM tags WHERE tags = ?)
    FROM offers WHERE offer = ? AND company = ?)
    

    Please note that You should use id_tags instead of tag name in your queries. Only use descriptive attributes in filtering the list for end user. Otherwise, use primary key columns.

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

Sidebar

Related Questions

I will try to explain the problem that I have with this code. This
I have a problem and I will try to explain the issue: I have
I am having difficulty to explain this problem, but I will try anyway. I
I will try to explain my problem. I have 4 files index.html, event.js, start.js
I have CSS problems. I will try to explain my problem to you with
Okay, this scenario is a little complicated, but I will try to explain it
This might be a little hard to explain, but I will try. I want
Good day, i will try to explain my problem as best as i can.
I will try to explain what exactly I need to do. I have 3
this question might sound a little bit weired... But I will try to explain:

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.