I have these two tables in mysql:
create table a (
id INT NOT NULL,
valueA INT
);
create table b (
id INT NOT NULL,
valueB INT,
priority INT
);
Example data – table a:
1, 30 2, 35 3, NULL 4, 8 5, 50 6, NULL 7, 11 8, NULL
Example data – table b:
1, 100, 1 2, 200, 2 3, 250, 3 4, 350, 4
And I want result:
30 35 100 8 50 200 11 250
I want select a.valueA. If in a.valueA is a NULL value I want to replace it with b.valueB. The first occurrence of NULL in a.valueA I want to replace with b.valueB where priority = 1, the second occurrence of NULL in a.valueA I want to replace with b.valueB where priority = 2 and so on.
Please guys, don´t you have any idea how to solve this select in mysql?
Thanks.
Is this what you want? :