Where clause only for a number of columns

72 Views Asked by At

I've tried looking at similar questions but couldn't find my exact use case, apologies if this is a duplicate (knowing how big this website is it probably is so sorry!)

I'm completely new to SQL and have managed to put the following together:

GPCUST.DISPUTET,
> GPCUSTEXT.FIELD_VALUE WHERE METAFIELD_ID = '11',

> GPCUSTEXT.FIELD_VALUE WHERE METAFIELD_ID = '12',

> GPCUSTEXT.FIELD_VALUE WHERE METAFIELD_ID = '13',

FROM GPCOMP20.GPCUST

LEFT JOIN GPCOMP20.ARCUST ON GPCUST.CUSTNO=ARCUST.CUSTNO

RIGHT JOIN GPCOMP20.GPCUSTEXT ON GPCUST.CUSTNO=GPCUSTEXT.CUSTNO

WHERE GPCUST.COMPANY IS NOT NULL

So the 3 WHERE clauses after the 3 columns that are all GPCUSTEXT.FIELD_VALUE only apply to that exact column thus bringing in a different piece of data for each. As it stands it's giving me a red error line under the comma behind each clause saying " incorrect syntax near "," " so it must be wrong the way I'm trying to do it.

I'm using Azure Data Studio and our server is Microsoft SQL Query (I believe this makes a difference to the way I code above?).

Any help would be greatly appreciated!

EDIT

The GPCUSTEXT table looks as follows when searching on one particular CUSTNO:

custno field_value metafield_id
12345 value1 11
12345 value2 12
12345 value3 13

So the result of my query I'm trying to compile should look like below for this same custno:

custno disputet field_value field_value field_value
12345 100.00 value1 value2 value3
0

There are 0 best solutions below