Skip to content
Advertisement

Join two tables bring mismatch values MYSQL

I have two tables with >4million records i need to make a select query with where two columns match bring both tables value on this match and then i will insert that into a 3rth table:

This is table A: (bitfinex)

enter image description here

This is table B: (Kraken)

enter image description here

I need to do a SELECT where timestamp and exchange_pair matches, as you can see in this image from table B the same timestamp can have multiple exchange_pair, what i need to do is match those with the other table columns and bring both table content

enter image description here

this was the query i used at once but when analyzing the results i had some mismatch values on the joins ( i did not found the relation, it was not either timestamp or the exchange pair) i wonder if my query syntax is right for the result im looking for.

im still confused if using inner join or just join, also i added the “Where” clause to make sure exchange pair and timestamp matches.

Advertisement

Answer

How about:

I recommend that any question about SQL queries are supplemented with scripts to enable quick and effective setup of needed tables and contained data, so that query writing can commence as soon as possible. It’s good for the sender to know how to do this, it’s good for the receiver because answering the question can begin once tables and data are in place.

I admit that in this particular case, the solution might be simple enough not to have to go through the whole process, but nonetheless.

Here is an example of how such a script could look (for this particular question):

Step 1: Create the bitfinex table

Step 2: Create the kraken table

Step 3: Fill the bitfinex table with sample data (or real data for that matter)

  1. Fill the kraken table with data

    insert into kraken (timestamp, exchange_pair, ask_array_price) select timestamp, exchange_pair, rand() * 1000 from bitfinex

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement