SQL statement help needed

Archived from the original Sajha.com — preserved as posted, replies can no longer be added here.
Start a New Discussion
Archived Post

I need to write SELECT statement which will show list of columns (Name,City,State, etc) along with one row for each address for the customer with an email address of abcde@abc.com SELECT FirstName, LastName, Line1, City, State, ZipCode FROM Customers JOIN Addresses ON Customers.EmailAddress = EmailAddress; This works, but its showing all Customers... How can I create something which will only display associated customer name with desired email?

cp21 · Nov 16, 2015 12:38 PM · 25,304 views

23 Replies · Showing 21 - 23
Page 2 of 2

omg thanks all

cp21 · Nov 17, 2015 1:11 PM

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

prankster · Nov 17, 2015 1:16 PM

Assuming you are looking for shipping address: Query 1: select concat(FirstName,' ',LastName) as customer_name, email, concat(Line1,' ',Line2, ' ',City,' ',State,' - ',ZipCode) as shipping_address, phone as phone_number from customer c left outer join address a on (c.CustomerID = a.CustomerID) and (c.ShippingAddressID = a.ShippingAddressID); Query 2: passing email as parameter. select concat(FirstName,' ',LastName) as customer_name, email, concat(Line1,' ',Line2, ' ',City,' ',State,' - ',ZipCode) as shipping_address, phone as phone_number from customer c left outer join address a on (c.CustomerID = a.CustomerID) and (c.ShippingAddressID = a.ShippingAddressID) where email = {pass_email}; Query 3: Using named query select concat(FirstName,' ',LastName) as customer_name, email, concat(Line1,' ',Line2, ' ',City,' ',State,' - ',ZipCode) as shipping_address, phone as phone_number from customer c left outer join address a on (c.CustomerID = a.CustomerID) and (c.ShippingAddressID = a.ShippingAddressID) where email = :email_id;

Ruben123 · Nov 17, 2015 5:43 PM

This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.

Start a New Discussion

You might be interested in...

Recent Classifieds View all
Upcoming Events View all
Service Providers View all