Friday, March 9, 2012

Pull data from Two tables

I am new to SQL, as old as it is. I am not new to programming I
normally just use Access.

I have two tables for a little project manager I made. After updates I
sent an email to the user. I need to populate the user based on the
"Assigned To" field I use, but I only log the username and not the
email address. Is there a way to associate the "Assigned To" to the
User's account in the "User" table so that I can pull thier email
address through code?

Thanks
ChuckPlease post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are. Sample data is also a good idea, along with clear
specifications. It is very hard to debug code when you do not let us
see it.|||Thank you for the feedback, obviously your a genius, but I do not know
what to post since I already stated I am new to this. My question was
of a theory nature, as I do not know what DRI and contraints are.

I will try to simply my question even more...

1. I have a database with two tables Case and Users
2. When I finish updating a case I want to send an email to the
currently assigned users.
3. The email address is not stated in the Case table, so I would like
to know if there is a way when I guery the database I can also pull
data from another Table.|||Hey Chuck,

What you're talking about is the guts of SQL: the JOIN. A newsgroup is
really not the best place to learn how to write SQL (from the ground
up), because it's gonna take some practice (and some background
knowledge) before you're really ready to even ask a question. There's
a couple of really good books on basic SQL out there; I'd recommend Be
Forta's Sams Teach Yourself SQL in 10 Minutes as a good primer on the
language.

Anyway, I think you might be looking at something like the following:

SELECT * --* is bad in production
FROM [CASE] c JOIN [Users] u ON c.[Assigned to] ON u.[UserName]

--note that case is a reserved word in SQL. Also, column names without
spaces are easier to manage.

Anyway, good luck on your quest.

Stu|||Ok, thought what I was thinking was more simple, but I understand that
its more of a loaded question.

Thanks for the feedback and suggestions, I will start reading up.

Chuck|||"cvillard" <cvillard@.gmail.com> wrote in message
news:1124752154.644452.160570@.f14g2000cwb.googlegr oups.com...
> Thank you for the feedback, obviously your a genius, but I do not know
> what to post since I already stated I am new to this. My question was
> of a theory nature, as I do not know what DRI and contraints are.

DRI=Data Referential Integrity.

The important part is DDL - Data Definition Language.

What we need is the script to create your tables.

Something lie

CREATE TABLE cases (
case varchar(30),
case_id int
)

CREATE TABLE email (
case_id int,
case_email varchar(30)
)

DRI would include keys to make sure you can't have a case_id in email table
that doesn't exist in table cases, that case_email has a valid form, etc.

So, now

sounds like you want something like

select e.case_email from email as e inner join cases as c on
e.case_id=c.cases_id where e.case_id = 5

> I will try to simply my question even more...
> 1. I have a database with two tables Case and Users
> 2. When I finish updating a case I want to send an email to the
> currently assigned users.
> 3. The email address is not stated in the Case table, so I would like
> to know if there is a way when I guery the database I can also pull
> data from another Table.

No comments:

Post a Comment