Select values from one table based upon values in another...

How do I:

Select f1, f2, f3, from tb1 where f1=Select f1 from tb2 where f1='condition'?

Rex Winn
Code-frog System Architects, Inc.
VS 2005 Professional, C#, C++
0
codefrog
5/19/2006 4:52:03 AM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

3 Replies
743 Views

Similar Articles

[PageSpeed] 50

Well... You might try reading up on some standard sql syntax... There are a number of different ways...

Select t.f1,t.f2,t.f3

From tb1 t INNER JOIN tb2 t2 ON t.f1 = t2.f1

Where t2.f1 = 'condition'

 

Select t.f1,t.f2,t.f3

From tb1 t

Where t.f1 IN (

   Select t2.f1

   From tb2 t2

   where t2.f1 = 'condition')

 

Select t.f1,t.f2,t.f3

From tb1 t

Where exists (select t2.f1

              From tb2 t2

              where t1.f1 = t2.f1 AND t2.f1 = some condition)

 

Not sure what you're looking for... but you may not even need to use table 2...

Select f1,f2,f3,

From tb1

Where f1 = 'Condition'

0
TGnat
5/19/2006 1:41:21 PM
I actually forgot you can do a:

Select t1.f1, t1.f2, t1.f3 from t1, t2 where t1.f2 = t2.f2 (going off memory that may not be right but it's right in my code).

- Thanks :)

Rex Winn
Code-frog System Architects, Inc.
VS 2005 Professional, C#, C++
0
codefrog
5/19/2006 3:28:05 PM
Yup... But use a join... It's a new century afterall!
0
TGnat
5/19/2006 3:37:10 PM
Reply:

Similar Artilces:

Add values to a table based on values in another table
When a record is inserted or updated records in Table1 I want a record to be inserted into table3 for each record ID that is in table2 if the table2.id does not already exist in table3. What is the best way to do this? Could this be done with a trigger? If it could how would I write such a trigger. I have never written one before and this sounds like a hand full for my first effort. Your help will be greatly appreciated. Thanks You could do it in a trigger.  They're really not hard.  It's just SQL you want to run whenever a certain action happens on your table.  Pretty st...

Setting the datasource of one dropdown box based on the values selected in another
As the title says, how is this done.I thought it would as simple as saying something like:If dropdown1 SelectedValue = 1 Then    dropdown2.datasource = 'what's the exact syntax here?End ifCan someone let me now how this is done please? TIA,Mo    dropdown2.datasource = 'The list of data you want to bind.'don't forget to putdropdown2.databind();to bind the dropdown to your new datasource   Thanks very much for the prompt reply Bart. I've tried what you suggested and which works - sort of! I probably didn't explain my...

Selecting value in one field then causes value in another field to be selected.
I have a web form which contains a date field, the date is populated using a DatePicker which is Javascript based. The form also has a drop down box containing 3 values. What I want to do is when a date has been selected that this will cause the dropdown list value to change to dated which is one of its 3 values. i.e. when the date field is not blank then the value will be selected in the dropdown. What I also want to happen is when the date has been selected and the dropdown value is dated then the date field and the dropdown field will be set to read only.Anyone any ideas how to this usin...

DropDownList bound to one table, selected value from another table
Hi I am having a very frustrating problem with a DropDownList.  The DropDownList is bound to one SQL Server 2005 table.  I do this progromatically with the following code:Public Sub EvaltrID() TryDim aType As String = txtAircraftType.SelectedValue Dim auth As String = Convert.ToInt32(MinLevel.Text) Dim active As String = "True" Dim iPilot As String = "True"Dim CrewPos As String = txtCrewPos.SelectedValue Dim CrewPos1 As String = "SO" Dim instructSO As String = "True"Dim sesType As String = txtSessionType.Text Dim sesType1 As String ...

DropDownList bound to one table, selected value from another table
I posted this in another forum topic and I'm not getting any response.  I'm hoping maybe I will ge more help here since it pertains to a server control.  Hi I am having a very frustrating problem with a DropDownList.  The DropDownList is bound to one SQL Server 2005 table.  I do this progromatically with the following code:Public Sub EvaltrID() TryDim aType As String = txtAircraftType.SelectedValue Dim auth As String = Convert.ToInt32(MinLevel.Text) Dim active As String = "True"Dim iPilot As String = "True" Dim CrewPos As Strin...

Select the value from a field of one table and place it into another table.
Using VB.NET, VS2005, SQL Server 2000. In a Windows Form, how could I provide a means for a user to select the value from a field of one table (a primary key value) and place it into another table (as a foreign key value)? The goal is to "assign" a person from one table to a location in another table by placing the person's primary key value into the location's foreign key field via an easy to use "selection" mechanism like a DataGridView or something.Thanks in advance for any help or examples.David  this is an ASP.Net forum - - you might want to check out: http://forums.microsof...

Copy values from one table to another table using LINQ to SQL?
Hello,I have two database tables that have different names but identical structure (columns).What is the easiest way to copy the values from one table to the other table using LINQ to SQL? Thanks,-- shawn shawn Hi, As far as I research, we could use "foreach"  to insert the data from one table to another table. The code is shown below.         //there exist two table list and listSecond        DataClassesDataContext dataClass = new DataClassesDataContext(); //create the instance of the DataCon...

Setting the value of a RadioButtonList based on a value in my sql table.
Hi folks, From a Sql database table I'm trying to display a RadioButtonList with two text values, "Buy" and "Sell". The actual numeric values in my table are 1 (Buy) or 2 (Sell). The name of the column in the table is "buy_sell". So how do I set the SELECTED="TRUE" property in the ListItem based on the value of my buy_sell column ? <asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1" OnInit="FormView1_Init"> .. .. <EditItemTemplate> <td><asp:RadioButtonList  DataSourceID="ObjectDataSource1" DataValueField="buy_sell" DataTextField...

Passing value from one control to another and inserting that value in a table
Hey all, sorry if the subject is confusing or has already been covered, but I have (obviously) a problem (at least one).This is using:Visual Studio 2005ASP.NET 2.0SQL Server 2005 ExpressVisual Basic I'm building a CRM system for my company and have run into a snag when attempting to add new customer records for a given client. The first thing that any CSR (or admin) must do upon accessing the CRM system is choose which client's customers they are actually working with (we have multiple clients and are ultimately responsible for providing customer service to the clients' end ...

Enabling the edition of an extended attribute value based on the value of another one
Hello! I'm using PowerDesigner 15 and I construted an extended model (.XEM) for PDM that has 2 extended attributes for tables, named A and B. Now, I want to enable the value edition of attribute B (type Text) only if attribute A is set to "No" (possible values: 'Yes' and 'No'). Is it possible? Thank you! This is a multi-part message in MIME format. ---=_forums-1-dub4b72cb6c Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit Hi Mila, yes you can. You have to create a criterion under the metaclass where ...

insert multiple values from one table into one column from another table?
Hi, I'm attempting to create an insert statement that gets the values from multiple columns and insert them into one column from another table, is there a simple solution to do this?Here is something similar to what i'm wanting done, just it's not the correct way to do it, i want value1, value2 and value3 from one table to be combined and put into the value1 column of another table, what am i doing wrong? INSERT INTO tablename2 (value1 + value2 + value3)SELECT value1FROM tablename1 thanks in advance! INSERT INTO tablename2 (SELECT val1 + val2 + val3 FROM tabl...

Getting a value from a SQL table displaying a specific page based on that value
May seem to newbie but here goes:I have a login page.  For the login I run a stored procedure with 4 return values, 0 - being valid, 1 - username exists already, 2 - username is incorrect3 - password is incorrectThis all works fine.  But from that I have the default page when the login credentials are correct.  The issue is I need to display a specific default page based on their location id from the member table which I already run a sp against for the login.  I have set up an .ascx page with a datagrid to display the results which works when I run the query for a h...

Within a SELECT, how do I replace an empty or null value with a value from another table?
Hello,I'm a beginner in SQL and I have been searching through the SQL Cookbook and Google but I can't seem to find an example of what I want to do. I want to create a report that will return names and emails using two of my tables. I want to use the email in my primary table in the select but if it is null or empty I want to replace it with an email from my secondary table. Below is what I would like to do but I got a syntax error with it in SQL Server 2000. SELECT MemberID As ID, MemberFirstName As FirstName, MemberLastName As LastName, (IF MemberEmail = &#...

Change Another Column Value based on Dropdownlist selected value while gridview onrowediting
Hi everyone. Another gridview question again. I have a gridview, with three columns, Code, Description and Action. The Code column, when I click on the Edit linkbutton on the Action column becomes a dropdown list. How can I do that when I selected a value from the dropdownlist, the value of the description on would be changed to the description corresponding to the dropdownlist? Thanks.   Hi:   From your description I think you can try: 1. Set AutoPostBack=true for your DropDownList. 2. protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) &n...

Web resources about - Select values from one table based upon values in another... - asp.net.sql-datasource

Here's Our First Look at Bran Stark in Game of Thrones Season Six
When we first met Game of Thrones ’ Bran Stark, he was a tower-climbing scamp who had a most unfortunate encounter with Jaime Lannister. As Entertainment ...

Ohio grand jury clears police in fatal shooting of 12-year-old
A grand jury cleared two Cleveland police officers on Monday in the November 2014 fatal shooting of 12-year-old Tamir Rice, who was brandishing ...

How Can Bernie Possibly Sway Trump Supporters?
Trump: "Whaddya gonna do, talk SENSE to my supporters?" Joseph Sohm / Shutterstock.com Donald Trump and Bernie Sanders are the only interesting ...

Ashley Madison: We’ve Added 4 Million Members Post-Hack
I suppose you could say that this particular claim has a tone of defiance around it – Ashley Madison, the dating site that was exposed to a hack ...

Gallantry medal for police dog killed after Paris attacks
A French police dog killed in a security services raid after the Paris attacks is to receive a posthumous medal for gallantry from a British ...

Iraqi Military Reclaims Ramadi from ISIS After Months-Long Siege
Following several months of fighting, Iraqi forces, supported by a U.S.-led airstrikes, drove Islamic State fighters out of the center of Ramadi, ...

Baby Survives After Man Allegedly Fatally Hits Pregnant Woman With Car on Christmas Eve
Baby Survives After Man Allegedly Fatally Hits Pregnant Woman With Car on Christmas Eve

Alleged Samsung Galaxy S7 Cases Leaked
The Samsung Galaxy S7, if the rumors are to be believed, will be launched in February 2016 . The phone is highly-anticipated but if you were ...

Meadowlark Lemon, Harlem Globetrotters’ Dazzling Court Jester, Dies at 83
Meadowlark Lemon, whose halfcourt hook shots, no-look behind-the-back passes and vivid clowning were marquee features of the feel-good traveling ...

NFL to investigate report of HGH shipments to Peyton Manning
USA TODAY NFL to investigate report of HGH shipments to Peyton Manning USA TODAY Peyton Manning and several of his NFL colleagues have vigorously ...

Resources last updated: 12/29/2015 1:12:41 AM