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

How to select 2 tables

P: n/a
Hi

I need to select 2 tables . The field 'p_description' is not always
aviable but i still need to print it to the screen
SELECT *
FROM task,p_description
WHERE ComponentIDLink = 34 OR task.TaskID = p_description.pTaskLink
GROUP BY TaskID ORDER BY TaskName

If i use AND it works, but there are colums missing

Is it possible in a OR that there is a default value ?
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Gerald Maher wrote:
I need to select 2 tables . The field 'p_description' is not always
aviable but i still need to print it to the screen
I think you are mixing up terminology a little bit. In your example,
p_description is a table, not a field. pTaskLink and TaskID are fields.

When you say "is not always available" what do you mean? Do you mean
that there not every row in the task table has a corresponding row in
the p_description table?
SELECT *
FROM task,p_description
WHERE ComponentIDLink = 34 OR task.TaskID = p_description.pTaskLink
GROUP BY TaskID ORDER BY TaskName
This is called an inner join. It returns a row only when there is an
equal value in both the task table and the p_description table.
If i use AND it works, but there are colums missing


I think you mean that there are rows missing, not columns. If so, you
need to use an outer join. An outer join is where you get every row in
one table, even if there aren't any matching rows in the other table.
In those cases, the values for the second table are returned as NULL.

SELECT t.*, p.*
FROM task t LEFT OUTER JOIN p_description p ON t.TaskID = p.pTaskLink
WHERE t.ComponentIDLink = 34
GROUP BY t.TaskID
ORDER BY t.TaskName

I'm guessing at which field is in which table, because I can't be
certain from your example query.

I think you need to study some basics about databases and queries, so
you can understand inner and outer joins, and also so you can use
correct terminology when you ask questions. It'll make the questions
clearer and people will be able to answer more accurately.

Regards,
Bill K.
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.