I need help with this select

Asked

Viewed 26 times

1

I have the following tables

CAMPO1_FK

103
103
103
103
103
103
103
103
103
103
103
103
103
103
103
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
108
434
434
434
434
434
434
434
434
434
434
434
434
434
434
434
434
434
434
434
434
434
434
434
4082
4082
4082
4082
4082
4082
4082
4082
4082
4082
4082
4082
4082
4082
4082
6394
6394
6394
6394
6394
6394
6394
6394
12315
12315
12315
12315
12315
12315
12315
12315
12315
12315
12315

CAMPO2_FK

196
190
138
136
136
134
133
130
129
128
125
124
121
119
118
190
189
188
187
186
185
182
182
181
174
173
164
163
162
160
159
157
149
149
149
148
146
145
144
143
142
140
140
130
129
128
125
124
190
189
188
182
182
181
178
173
168
168
168
163
162
161
153
147
145
144
143
136
134
130
120
190
189
188
184
182
173
168
163
162
161
154
136
135
127
126
190
189
188
184
182
156
136
134
198
197
190
189
188
184
182
163
162
136
134

What I need to do is get the maximum number of the CAMPO2_FK for each of the CAMPO1_FK.

For example:

103-196 / 108-19 [...] 

1 answer

0


You can use the command MAX(CAMPO2_FK) to get the most value, then use the group by CAMPO1_FK to filter this value for each of the fields you need.

Ex:

SELECT MAX(CAMPO2_FK) from SuaTabela group by CAMPO1_FK

This select will list you the highest value of CAMPO2_FK, for each change in the CAMPO1_FK.

I hope I’ve helped you, in case there are any questions, I’m willing to help you.

  • 1

    That’s right !! Thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.