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

The Archive Base Latest Questions

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

I’m having some problems with join query. What I want is select rows of

  • 0

I’m having some problems with join query. What I want is select rows of two tables that have some similar states, others no. And I have a state-equivalence view

Table Sales:
ID  .....   StateID
1           1
2           1
3           6

Table Orders
ID  .....   StateID
11          2
12          2
15          3

Table StatesEquivalence
ID  SalesState   OrdersState    StateName
1   1            2              Attended
2   2            3              Declined

I’ve made a union of both tables(Sales and Orders) and I want a column with the EquivalentStateID and the StateName by doing something like this:

SELECT sales.ID as ID,equivalence.ID as State,equivalence.StateName
FROM Sales
INNER JOIN StatesEquivalence as equivalence
ON sales.StateID = equivalence.SalesState
WHERE sales.ID = 1
UNION
SELECT orders.ID as ID,equivalence.ID as State,equivalence.StateName
FROM Orders as orders
INNER JOIN StatesEquivalence as equivalence
ON orders.StateID = equivalence.OrdersState

Somehow I am obtaining wrong information on the equivalentID

ID      State        StateName
1       2            Attended
2       2            Attended
11      2            Attended
...

I don’t know what happend.. because the statename is correct, but the StateID is showing wrong information

The table might show this:

ID      State        StateName
1       1            Attended
2       1            Attended
11      1            Attended
...
  • 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-28T14:22:10+00:00Added an answer on May 28, 2026 at 2:22 pm

    I don’t think you are showing us the real problem code. I did the following:

    begin transaction
    
    create table sales (id int, stateid int)
    create table orders (id int, stateid int)
    create table statesequivalence (id int, salesstate int, ordersstate int, statename varchar(20))
    
    insert into sales values (1, 1)
    insert into sales values (2, 1)
    insert into sales values (3, 6)
    
    insert into orders values (11, 2)
    insert into orders values (12, 2)
    insert into orders values (15, 3)
    
    insert into statesequivalence values (1, 1, 2, 'Attended')
    insert into statesequivalence values (2, 2, 3, 'Declined')
    
    SELECT sales.ID as ID,equivalence.ID as State,equivalence.statename
    FROM Sales
    INNER JOIN statesequivalence as equivalence
    ON sales.StateID = equivalence.SalesState
    WHERE sales.ID = 1
    UNION
    SELECT orders.ID as ID,equivalence.ID as State,equivalence.StateName
    FROM Orders as orders
    INNER JOIN statesequivalence as equivalence
    ON orders.StateID = equivalence.OrdersState
    
    rollback
    

    Result:

    ID          State       statename
    ----------- ----------- --------------------
    1           1           Attended
    11          1           Attended
    12          1           Attended
    15          2           Declined
    

    So, it works. Can you try the above code?

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.