0

Can you help me please? Trying to select those article numbers and pic paths that has the picture (some of them are without but it is not null). Is there some HAVING condition I can write? Or maybe just AND condition?

select a.artnr, p.path
from article a, photo p
where a.artnr = p.photo_nr
having ...and ...(?);

the table modell looks like this

4
  • Never use commas in the FROM clause. Always use proper, explicit, standard, readable JOIN syntax. Commented May 8, 2021 at 12:30
  • non-ANSI syntax uses commas. That's what the school teaches, wasn't my choice :) Commented May 8, 2021 at 12:36
  • . . That is really, really sad. The school should be teaching correct, standard syntax. Commented May 8, 2021 at 12:39
  • 1
    "That's what the school teaches, wasn't my choice" @GordonLinoff says that is sad. I'd say it's scary. Like going to a school for auto repair that teaches only carburetors and not fuel injection. What would be the "instructor's" ( I use the term very loosely in this case) if you were to present a solution with proper ANSI join syntax? If they reject it, that's even scarier. Commented May 8, 2021 at 15:25

1 Answer 1

1

if you are looking for paths that are not empty, then you should do this:

select a.artnr, p.path
from article a
join photo p on a.artnr = p.artnr_nr
where p.path <> ''

If you have to do it in the very old school way using commas, which I agree with the comments that is not a good practice, then

select a.artnr, p.path
from article a, photo p
where a.artnr = p.artnr_nr
and p.path<>''
Sign up to request clarification or add additional context in comments.

5 Comments

The path is not null and 'not empty', it just doesn't exist. It's not added for some articles - so no photo number or photo type either.
ok,then you don't need an extra condition, the join will only bring the articles that have something in photo. Please, notice that you have to join by a.artnr=p.artnr
The actual amount of tables is bigger and it looks like I'm missing something with joining the tables, because nothing is being returned (no data found). Thanks anyway! :)
If you need the data from say table X even when there is no match in table Y, consider X LEFT Join Y on X.key = Y.key
I went through all the joins and found the mistake. Took some time, though :-D Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.