I'm just starting to learn SQL, and so far (since two days ago) i managed to solve most of my problems, but now i need help.
The query below results in 1 column and row: "12345" and some extra rows with the value 0, that i need to get rid of.
SELECT product_id FROM sale_order_line WHERE order_id IN (SELECT id FROM sale_order WHERE name='S00062')
So i tried the following:
SELECT product_id FROM sale_order_line WHERE order_id IN (SELECT id FROM sale_order WHERE name='S00062') AND NOT product_id='0'
And now i get the result '12345' i was expecting. But when i try to get the name of the the column related to '12345' from another table....:
SELECT name FROM product_template WHERE product_variant_ids IN (SELECT product_id FROM sale_order_line WHERE order_id IN (SELECT id FROM sale_order WHERE name='S00062') AND NOT product_id='0')
I get an error saying: "Cannot compare data type of integer to string". Somehow it appears the code above tries to read product_id with all the 0s before they're all removed. I'm guessing.
But, if i do it directly, like:
SELECT name FROM product_template WHERE product_variant_ids = '12345'
It works! How can i fix this? Please forgive my newbie coding skills.