SQL statement help needed
First of all, I am not sure why there is an emailaddress in Address table. That's just bad table design. That just violates normal form of DB design and you will end up storing tons of redundant data.
If possible redesign your table like this
Customers- contains customerid,First name last name, emailaddress
Address- Contains addressid,City State, zipcode
customeraddressBridge- customerid and addressid
Then
Select C.FirstName, C.LastName,A.City,A.State,A.Zipcode
From Customer C
join customeraddressBridge CAB
on CAB.CustomerID=C.CustomerID
join Address A
on A.AddressID=CAB.AddressID
If this is not what you are looking for then give some example what you are looking for. It's not very clear from your question.
Wait a second, Does your Address table really contains EmailAddress field? I hope not. If that's the case I really don't know what are you trying to do because you completely screwed up the entire query. Basically what you are doing is you are not joining two tables, you are joining a table with same table with Email address. So of course you will get all the emailaddress from customers. I am pretty much sure you didn't build those table according to your level of writing queries. Do you really understand the join? If not stop what you are doing and study join first because it looks like what you are asking is completely messed up.
I have to join both tables. And No, Addresses does have have email address. Addresses contains their physical addresses. Customers has their email and such.
I need to return listed columns along with one row for each address for the customer with an email address of abcde@abc.com
lol, ok Then why are you joining a table which can not be joined? Now I know what's your problem is. There must be a table which has a mapping between your customer table and address table in your database. Find that table and above query
i.e
Select C.FirstName, C.LastName,A.City,A.State,A.Zipcode
From Customer C
join customeraddressBridge CAB
on CAB.CustomerID=C.CustomerID
join Address A
on A.AddressID=CAB.AddressID
You are completely missing key table which is a bridge or mapping table
@cp21 if u need IT help, u know where to turn.
DANG !!!
he said he is too busy marinating some meat poles with his mouth.
LOL
no offense, was just joking.
Lets, see if you are trying to do following,
Customer_table
--------------------
Customer_Id | Customer_Name | Customer_City | Customer_State
Email_Id_table
------------------
Customer_Id | Customer_Email_Id
Select C.Customer_Id, C.Customer_Name, C.Customer_City, C.Customer_State, E.Customer_Email_id From Customer_table C Join Email_Id_talbe E on
C.Customer_Id = E.Customer_Id
Here is the sqlfiddle,
http://sqlfiddle.com/#!6/655f9/4
Try this...
SELECT Name,City,State--,(add more cols as needed)
FROM ADDRESS a --(assuming thats your table name)
JOIN customer c ON a.customerid= c.customerid --(assuming customer is the table name and customerid is the common column)
WHERE c.emailaddress = 'abcde@abc.com' --(assuming emailaddress is the column that has email for the customer)
Last edited: 17-Nov-15 10:40 AM
Last edited: 17-Nov-15 11:53 AM
Last edited: 17-Nov-15 11:54 AM
"This statement doesn't return anything." does it error out....i dont think it would.
replace your last line with...
Where rtrim(ltrim(c.emailaddress)) = 'allen.sherwood@yahoo.com'
Last edited: 17-Nov-15 12:03 PM
Doesn't show any error, it compiles, but doesn't show any results.
use the trim logic in the on clause as well.
you have the email address misspelled.....its "allan" not "allen"!
use copy paste option...limits human error!
With small difference,
http://sqlfiddle.com/#!6/433b6/8
Please log in to reply to this post
You can also log in using your Facebook