SQL statement help needed - Sajha Mobile
SAJHA MOBILE
SQL statement help needed
Posts 20 · Viewed 10769 · Go to Last Post
virusno1
· Snapshot 28
Like · Likedby · 0

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.
virusno1
· Snapshot 40
Like · Liked by · 0
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.
cp21
· Snapshot 70
Like · Liked by · 0
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
virusno1
· Snapshot 86
Like · Liked by · 0
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
bairaghi
· Snapshot 165
Like · Liked by · 0
@cp21 if u need IT help, u know where to turn.
DANG !!!
cp21
· Snapshot 187
Like · Liked by · 0
?
bairaghi
· Snapshot 189
Like · Liked by · 0
@RK
LOL
cp21
· Snapshot 207
Like · Liked by · 0
he said he is too busy marinating some meat poles with his mouth.
bairaghi
· Snapshot 209
Like · Liked by · 0
LOL
no offense, was just joking.
cp21
· Snapshot 244
Like · Liked by · 0
LOL i know
prankster
· Snapshot 395
Like · Liked by · 0
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
SolveSQL
· Snapshot 408
Like · Liked by · 0
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
NepaliBhai
· Snapshot 423
Like · Liked by · 0

Last edited: 17-Nov-15 11:53 AM
NepaliBhai
· Snapshot 423
Like · Liked by · 0



Last edited: 17-Nov-15 11:54 AM
SolveSQL
· Snapshot 486
Like · Liked by · 0
"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
cp21
· Snapshot 499
Like · Liked by · 0
Doesn't show any error, it compiles, but doesn't show any results.
SolveSQL
· Snapshot 533
Like · Liked by · 0
use the trim logic in the on clause as well.
SolveSQL
· Snapshot 537
Like · Liked by · 0
you have the email address misspelled.....its "allan" not "allen"!

use copy paste option...limits human error!
cp21
· Snapshot 567
Like · Liked by · 0
omg

thanks all
prankster
· Snapshot 575
Like · Liked by · 0
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
View in Desktop
What people are reading
You might like these other discussions...
· Posts 1 · Viewed 143
· Posts 7 · Viewed 1610
· Posts 4 · Viewed 353 · Likes 1
· Posts 1 · Viewed 67
· Posts 1 · Viewed 67
· Posts 5 · Viewed 490
· Posts 1 · Viewed 128
· Posts 1 · Viewed 227
· Posts 2 · Viewed 375
· Posts 1 · Viewed 112



Your Banner Here
Travel Partners
Travel House Nepal