473,651 Members | 2,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to select 2 tables

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_descript ion
WHERE ComponentIDLink = 34 OR task.TaskID = p_description.p TaskLink
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
1 2265
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_descript ion
WHERE ComponentIDLink = 34 OR task.TaskID = p_description.p TaskLink
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.ComponentIDLi nk = 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
12542
by: mfyahya | last post by:
I have two tables, both containing an 'authors' column. Is there a way to get a unique list of authors from the two tables? I tried SELECT DISTINCT `authors` from `table1`, `table2`; but I got an "Column 'authors' in field list is ambiguous" error. Is there also a query to return only the count of distinct authors from the two tables? Thanks for any help.
1
11568
by: Ahmet Karaca | last post by:
Hi. myds.Reset(); mycommand.SelectCommand.CommandText= "Select att1 from Ing as Ingredient, Pro as Product "+ "where Pro.ad='apple' and Pro.id=Ing.id"; mycommand.Fill(myds, "Product"); // Here is the problem listbox.DataSource = myds.Tables.DefaultView; // Here again listbox.DataTextField = "invid"; // Here again listbox.DataBind(); mycon.Close()
1
4032
by: Diffident | last post by:
Hello All, I am trying to filter rows in a datatable based on filtercriteria and sortcriteria using the datatable.select() method. I am encountering a strange behavior in this process. Here is what I am trying to do... ---------
4
5668
by: VK | last post by:
Hello, I have a dataset which has one datatable in it. The dt has over 3000 rows in it. Now I would like to get the rows where the StartDate is 15 Feb 2005, so I did the following: ds.Tables(0).Select("StartDate = '15/02/2005'") However this returns me only 3 rows. I have tried other possiblities like:
7
2992
by: Matt Jensen | last post by:
Howdy Fairly simple question I think, I presume the answer is no it can't be reused for 2 *SELECT* statements, but just hoping for clarification. Just asking in the interests of trying to minimise code. i.e. if the SqlDataAdapter uses a connection to the one database for a select statement and I want to do a second select statement on exactly the same database, can I reuse the SqlDataAdapter? I ask because I want to put both 'select'...
33
6648
by: Peter | last post by:
People are telling me it is bad to put select * from <atable> in a view. I better should list all fields of the table inside the definition of the view. I dont know exactly why but some say: A select * from makes sql server does a table scan.
4
7192
by: Chris | last post by:
Can't seem to figure out how to do this and have been reading for some time now...... I want to select a row count from a table name in SYSTABLES. This statement does not return what I needed, but can help explain what I'm looking for. I want the results to be the Row Count from a Table Name out of the Sub-Select. Select Count(*) from
10
1718
by: Richard Maher | last post by:
Hi, Sorry if this is one of those issues that people feel passionate about and I assure you I'm not trolling but rather seeking guidance on which way to go with the web browser presentation of tabular result sets. I'm a newbie and don't know any better, but I immediately opted for Select Lists 'cos A) someone showed me :-) and b) 'cos I didn't think you could select from a Table without a Button-cell on each row (but a recent post of...
3
25680
by: Jeff | last post by:
hey ..NET 2.0 I have a datatable which consist of 3 columns (int, date, value). This DataTable have 3 rows, the values of the "date" ("date" column is of datetime datatype) column is: 2007-09-15 00:00:00.000 2007-10-15 00:00:00.000 2007-11-15 00:00:00.000
0
1516
by: cmrhema | last post by:
Hi, I have two controls one html select control and one asp.net dropdownlist control. In html select control i have three maps loaded. It is loaded in the following manner. <SELECT class="TextBoxLabel" id="ddlMap" style="WIDTH: 128px;" tabIndex="1" onchange="fnChangeMap();" name="ddlMap" runat="server">
0
8352
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8697
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8465
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8579
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7297
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2699
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1587
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.