473,387 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how do I query this?

Hi,

I have a table that stores a list of IDENTITIES that references
different tables. Two rows in this table refreence the same key from
a table:

tbl_myTable(myTableID, swUserID, hwUserID, etc...)
tbl_user (userID, userName)

where swUserID and hwUserID references userID of the tbl_user table.

How do I do make a query to return the userName of both swUserID and
hwUserID?
Jul 20 '05 #1
3 1200
To get them as a single row:
--
Anith
Jul 20 '05 #2
To get them as a single row:

SELECT u1.*, u2.*
FROM mytbl t1
INNER JOIN usertbl u1
ON u1.userID = t1.swUserID
INNER JOIN usertbl u2
ON u2.userID = t1.hwUserID ;

To get them as two rows:

SELECT u1.*
FROM mytbl t1
INNER JOIN usertbl u1
ON u1.userID IN (t1.swUserID, t1.hwUserID) ;

--
Anith
Jul 20 '05 #3
hy****@hotmail.com (Hyrum Mortensen) wrote in message news:<28*************************@posting.google.c om>...
Hi,

I have a table that stores a list of IDENTITIES that references
different tables. Two rows in this table refreence the same key from
a table:

tbl_myTable(myTableID, swUserID, hwUserID, etc...)
tbl_user (userID, userName)

where swUserID and hwUserID references userID of the tbl_user table.

How do I do make a query to return the userName of both swUserID and
hwUserID?


This may be what you're looking for:

select
t.myTableID,
u1.userName as 'swName',
u2.userName as 'hwName'
from
dbo.tbl_myTable t
join dbo.tbl_user u1
on t.swUserID = u1.userID

join dbo.tbl_user u2
on t.hwUserID = u2.userID

If this doesn't help, please post CREATE TABLE statements for both
tables, as well as sample data and the output you expect to see.

Simon
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: joemyre | last post by:
Hi everyone, What I'm trying to do is take php variables i got from user input, and pass them as the MySQL query terms. $query = "select * from ident where ".$searchtype1."=".$searchterm1."";...
16
by: cover | last post by:
I have a form with drop down menus to query for name, month, and year to capture activity accordingly by an individual for a given month and given year. But I'd like to also be able to query ALL...
3
by: Nick Truscott | last post by:
<? // scoreinput.php - input a match score when match selected from list ?> <html> <head> <basefont face="Verdana"> </head> <body>
0
by: ChangAya | last post by:
I use binary log on mysql system. Yesterday i found some hacking attempt on my machine. ( I found some unknown queries on binary log) But i don't get any information about hacking query...
8
by: Együd Csaba | last post by:
Hi All, how can I improve the query performance in the following situation: I have a big (4.5+ million rows) table. One query takes approx. 9 sec to finish resulting ~10000 rows. But if I run...
4
by: Steve | last post by:
I have a products table where the PK is ProductID. Also have the standard Orders table and OrderDetails table. I created a query that joins the Orders table and OrderDetails table. The query...
3
by: Tom Mitchell | last post by:
All: I'm stumped on a query. How do I find duplicates in a table where one of the duplicates has values is a certain field and the other doesn't. For example, I have the following table: ...
1
by: Nicolae Fieraru | last post by:
Hi All, I want to find if there is a different way than the way I am working now. Lets say I have a table, tblCustomers containing address details. I want a report with all the customers from...
5
by: Ryan Hubbard | last post by:
Is it possible to get the recordset from an open query window? So you run the query. The window is open. Can vba retrieve this data?
21
by: CSN | last post by:
I have a pretty simple select query that joins a table (p) with 125K rows with another table (pc) with almost one million rows: select p.* from product_categories pc inner join products p on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.