[Show all top banners]

virusno1
Replies to this thread:

More by virusno1
What people are reading
Subscribers
:: Subscribe
Back to: Computer/IT Refresh page to view new replies
 SQL statement help needed
[VIEWED 10371 TIMES]
SAVE! for ease of future access.
Posted on 11-16-15 1:04 PM     [Snapshot: 28]     Reply [Subscribe]
Login in to Rate this Post:     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.
 
Posted on 11-16-15 1:11 PM     [Snapshot: 40]     Reply [Subscribe]
Login in to Rate this Post:     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.
 
Posted on 11-16-15 1:20 PM     [Snapshot: 70]     Reply [Subscribe]
Login in to Rate this Post:     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
 
Posted on 11-16-15 1:30 PM     [Snapshot: 86]     Reply [Subscribe]
Login in to Rate this Post:     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
 
Posted on 11-16-15 3:08 PM     [Snapshot: 165]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

@cp21 if u need IT help, u know where to turn.
DANG !!!
 
Posted on 11-16-15 3:32 PM     [Snapshot: 187]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 
 
Posted on 11-16-15 3:34 PM     [Snapshot: 189]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 
 
Posted on 11-16-15 3:57 PM     [Snapshot: 207]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

he said he is too busy marinating some meat poles with his mouth.
 
Posted on 11-16-15 3:59 PM     [Snapshot: 209]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

LOL
no offense, was just joking.
 
Posted on 11-16-15 4:26 PM     [Snapshot: 244]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 
 
Posted on 11-17-15 10:21 AM     [Snapshot: 395]     Reply [Subscribe]
Login in to Rate this Post:     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

 
Posted on 11-17-15 10:39 AM     [Snapshot: 408]     Reply [Subscribe]
Login in to Rate this Post:     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

 
Posted on 11-17-15 11:12 AM     [Snapshot: 423]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 


Last edited: 17-Nov-15 11:53 AM

 
Posted on 11-17-15 11:12 AM     [Snapshot: 423]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 



Last edited: 17-Nov-15 11:54 AM

 
Posted on 11-17-15 12:03 PM     [Snapshot: 486]     Reply [Subscribe]
Login in to Rate this Post:     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

 
Posted on 11-17-15 12:11 PM     [Snapshot: 499]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Doesn't show any error, it compiles, but doesn't show any results.

 
Posted on 11-17-15 12:52 PM     [Snapshot: 533]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

use the trim logic in the on clause as well.
 
Posted on 11-17-15 1:00 PM     [Snapshot: 537]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

you have the email address misspelled.....its "allan" not "allen"!

use copy paste option...limits human error!
 
Posted on 11-17-15 1:11 PM     [Snapshot: 567]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 
 
Posted on 11-17-15 1:16 PM     [Snapshot: 575]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

With small difference,
http://sqlfiddle.com/#!6/433b6/8

 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 60 days
Recommended Popular Threads Controvertial Threads
डीभी परेन भने खुसि हुनु होस् ! अमेरिकामाधेरै का श्रीमती अर्कैसँग पोइला गएका छन् !
शीर्षक जे पनि हुन सक्छ।
What are your first memories of when Nepal Television Began?
Sajha Poll: नेपालका सबैभन्दा आकर्षक महिला को हुन्?
NRN card pros and cons?
Basnet or Basnyat ??
निगुरो थाहा छ ??
Nas and The Bokas: Coming to a Night Club near you
अमेरिकामा छोरा हराएको सूचना
Breathe in. Breathe out.
nrn citizenship
Top 10 Anti-vaxxers Who Got Owned by COVID
Doctors dying suddenly or unexpectedly since the rollout of COVID-19 vaccines
ढ्याउ गर्दा दसैँको खसी गनाउच
Sajha has turned into MAGATs nest
Send Parcels from USA to Nepal & Worldwide.
Why is every youths leaving Nepal? Why are not youths entering politics and serving the country, starting business etc?
if you are in USA illegally and ask for asylum it is legal
TPS Work Permit/How long your took?
महँगो अण्डाको पिकल्प : कुखुरा र खोर भाडामा लिने
Nas and The Bokas: Coming to a Night Club near you
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters