By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,354 Members | 600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,354 IT Pros & Developers. It's quick & easy.

optional select

bilibytes
100+
P: 128
hi,

i was wondering if it is possible to make a SELECT query with some optional fields.

i have "Object", "Info", "Image" Tables

the object contains the id and name of objects,
the info contains the additional information of each object and
the Image contains the image of each object.

BUT, not all objects have an image so when i perform this query:

Expand|Select|Wrap|Line Numbers
  1. SELECT o.name, inf.descritpion, inf.price, img.blob
  2. FROM object o, info inf, image img
  3. WHERE o.object_id = "12341234"
  4. AND inf.object_id = o.object_id
  5. AND img.object_id = o.object_id
  6.  
i get 0 results if the object has no image associated....

How could i perform this query to get all the results i query excepting those that don't exist?

I am figuring out now a solution to the problem, but it would populate the image table inefficiently:
when someone ads an object, without image, insert a row into images with the object id and with a default value for the image.

This would prevent from returning 0 results, but would also populate the "Image" Table unnecessarily

So if there is a query that allows you to make sort of a try{} please let me know

Thankyou,

bilibytes
Nov 12 '08 #1
Share this Question
Share on Google+
1 Reply

10K+
P: 13,262
Use RIGHT JOIN. i.e select from object right join image.
See the details in the reference manual.
Nov 13 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.