Hey everyone,
I am currently working with sql and I am struggling to find the right coding for this question:
Show an address list (CompanyName, Address, City, Country), combining Customers and Suppliers, sorted on country and city. The result table should have an extra field in which a Customer is registered with a ‘C’ (apostrophes!) and a Supplier with ‘S’. The column heading should be (AS) Cust_Supp.
so far I have this (a bit long winded but it works and shows all the correct fields)
SELECT Suppliers.SupplierID, Suppliers.CompanyName AS Suppliers_CompanyName, Suppliers.Address, Suppliers.City, Suppliers.Country, Customers.CustomerID, Customers.CompanyName AS Customers_CompanyName
FROM Suppliers INNER JOIN (Products INNER JOIN ((Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID) INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID) ON Products.ProductID = [Order Details].ProductID) ON Suppliers.SupplierID = Products.SupplierID;
How would I sort by country and city as well as creating an extra field AS. Any help welcome!
10 1351
SELECT Suppliers.SupplierID, Suppliers.CompanyName AS Suppliers_CompanyName, Suppliers.Address, Suppliers.City, Suppliers.Country, Customers.CustomerID, Customers.CompanyName AS Customers_CompanyName
FROM Suppliers INNER JOIN (Products INNER JOIN ((Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID) INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID) ON Products.ProductID = [Order Details].ProductID) ON Suppliers.SupplierID = Products.SupplierID
ORDER BY Suppliers.Country, Suppliers.City;
>as well as creating an extra field AS.
I don't know what you mean.
Hey everyone,
I am currently working with sql and I am struggling to find the right coding for this question:
Show an address list (CompanyName, Address, City, Country), combining Customers and Suppliers, sorted on country and city. The result table should have an extra field in which a Customer is registered with a ‘C’ (apostrophes!) and a Supplier with ‘S’. The column heading should be (AS) Cust_Supp.
so far I have this (a bit long winded but it works and shows all the correct fields)
SELECT Suppliers.SupplierID, Suppliers.CompanyName AS Suppliers_CompanyName, Suppliers.Address, Suppliers.City, Suppliers.Country, Customers.CustomerID, Customers.CompanyName AS Customers_CompanyName
FROM Suppliers INNER JOIN (Products INNER JOIN ((Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID) INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID) ON Products.ProductID = [Order Details].ProductID) ON Suppliers.SupplierID = Products.SupplierID;
How would I sort by country and city as well as creating an extra field AS. Any help welcome!
The sql I posted brings up the fieldnames needed. I am just stuck on how to create the last part of the question: The result table should have an extra field in which a Customer is registered with a ‘C’ and a Supplier with ‘S’. The column heading should be (AS) Cust_Supp.
I can easily do the rest, yet this part is annoying me!
SELECT Suppliers.SupplierID, Suppliers.CompanyName AS Suppliers_CompanyName, Suppliers.Address, Suppliers.City, Suppliers.Country, Customers.CustomerID, Customers.CompanyName AS Customers_CompanyName
FROM Suppliers INNER JOIN (Products INNER JOIN ((Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID) INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID) ON Products.ProductID = [Order Details].ProductID) ON Suppliers.SupplierID = Products.SupplierID
ORDER BY Suppliers.Country, Suppliers.City;
You have set up a query to return a list of customers and their suppliers. Each record will have both so how do you want to distinguish between them. When do you want C and when S.
The sql I posted brings up the fieldnames needed. I am just stuck on how to create the last part of the question: The result table should have an extra field in which a Customer is registered with a ‘C’ and a Supplier with ‘S’. The column heading should be (AS) Cust_Supp.
I can easily do the rest, yet this part is annoying me!
The C has to be displayed if the field is referring to a customer and an S if referring to a supplier, for example:
ContactName Cust_supp
Bob s
Sorry for my lack of a better explanation, but if this helps this is the whole question:
Show an address list (CompanyName, Address, City, Country), combining Customers and Suppliers, sorted on country and city. The result table should have an extra field in which a Customer is registered with a ‘C’ and a Supplier with ‘S’. The column heading should be (AS) Cust_Supp.
Are you just trying to create one list with customers and suppliers if so your query is all wrong. You need a union query.
SELECT Suppliers.SupplierID As ID, Suppliers.CompanyName AS CompanyName, Suppliers.Address, Suppliers.City, Suppliers.Country, "S" As Cus_Supp
FROM Suppliers
UNION
SELECT Customers.CustomerID As ID, Customers.CompanyName AS CompanyName, "C" As Cus_Supp
FROM Customers;
SELECT Suppliers.SupplierID, Suppliers.CompanyName AS Suppliers_CompanyName, Suppliers.Address, Suppliers.City, Suppliers.Country, Customers.CustomerID, Customers.CompanyName AS Customers_CompanyName
FROM Suppliers INNER JOIN (Products INNER JOIN ((Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID) INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID) ON Products.ProductID = [Order Details].ProductID) ON Suppliers.SupplierID = Products.SupplierID
ORDER BY Suppliers.Country, Suppliers.City;
You have set up a query to return a list of customers and their suppliers. Each record will have both so how do you want to distinguish between them. When do you want C and when S.
I am trying basically to create a query which will show the customers details i.e. name, address and also showing the suppliers details name, address. Then an extra field should be created showing which is a supplier/customer represented by a C or an S. I know it is a really annoying question and even harder to explain it!
Did you try the union query I gave you?
By the way you have no address field in for customer.
I am trying basically to create a query which will show the customers details i.e. name, address and also showing the suppliers details name, address. Then an extra field should be created showing which is a supplier/customer represented by a C or an S. I know it is a really annoying question and even harder to explain it!
Yes I tried the one you gave me, I think it just needs tweeking a bit. As an error message of 'no matching fields in the customer table' or something (I am using a Dutch version so my translation is a bit bad!).
SELECT Suppliers.SupplierID As ID, Suppliers.CompanyName AS CompanyName, Suppliers.Address As Address, Suppliers.City As City, Suppliers.Country As Country, "S" As Cus_Supp
FROM Suppliers
UNION
SELECT Customers.CustomerID As ID, Customers.CompanyName AS CompanyName, Customers.Address As Address, Customers.City As City, Customers.Country As Country, "C" As Cus_Supp
FROM Customers;
Thanks I managed to get it working using this:
(SELECT ContactName, Address, City, Country, "'C'" AS Cust_Supp
FROM Suppliers)
UNION
(SELECT CompanyName, Address, City, Country, "'S'" AS Cust_Supp
FROM Customers)
ORDER BY Country, City
and thanks for your help =)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: laurie |
last post by:
Hi all,
I'm trying to help out a friend who has inherited a client with a PHP
shopping cart application. Neither of us know PHP, but I've been
muddling my way through, trying to get these old...
|
by: the_proud_family |
last post by:
HELP ME PLEASE!! my email is the_proud_family@yahoo.com
I can't get the ball to go up right side and then I need it to turn
around and keep turning until velocity=0 I have been at it for the
...
|
by: Kurt Watson |
last post by:
I’m having a different kind of problem with Hotmail when I sign in it
says, "Web Browser Software Limitations
Your Current Software Will Limit Your Ability to Use Hotmail
You are using a web...
|
by: Christo |
last post by:
borland c++ 5.01
character constant must be one or two characters long
get this when compiling my first c++ program can anyone out there help?
it is highlighting this line as the problem
...
|
by: x muzuo |
last post by:
Hi guys,
I have got a prob of javascript form validation which just doesnt work
with my ASP code. Can any one help me out please.
Here is the code:
{////<<head>
<title>IIBO Submit Page</title>...
|
by: Craig Keightley |
last post by:
Please help, i have attached my page which worksin IE but i cannnot get the
drop down menu to fucntion in firefox. Any one have any ideas why?
Many Thanks
Craig
...
|
by: JT |
last post by:
Help me the following C++ question:
Write a program to help a local bookshop automate its billing system.
The program should do the following:
(a)Let the user enter the ISBN, the system will...
|
by: tyler_durden |
last post by:
thanks a lot for all your help..I'm really appreciated...
with all the help I've been getting in forums I've been able to continue
my program and it's almost done, but I'm having a big problem that...
|
by: Jason |
last post by:
Hi,
I was wondering if any could point me to an example or give me ideas on how
to dynamically create a form based on a database table? So, I would have a
table designed to tell my application...
|
by: =?Utf-8?B?U2NvdHRSYWREZXY=?= |
last post by:
I'm creating a doc project for my c# program. I've done this before but this
time sonething is wrong. I build my doc project and is succeeds but when I
open the help file, there is no documentation...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| | |