Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I need help regarding SQL joins, i am trying join two tables as shown in below images
I guess you can try the below query to get the desired result -
SELECT CASE WHEN CT.partner2 IS NULL
THEN C.partner_id
ELSE CT.partner1
END Partner1,
CT.partner2,
C.Type,
C.Company_name,
C.First_name,
CT.city,
CT.Phone,
CT.Email
FROM CUSTOMER C
LEFT JOIN CONTACTS CT ON C.partner_id = CT.partner2
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 months ago.
Improve this question
how to rank each country based on number of people in SQL.
Try
SELECT * FROM (
SELECT country, count(people) as count FROM your_table GROUP BY country
) ORDER BY count DESC
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
This is the query image:
This result should appear as follows:
This is my query: select id, name, total where student.id= marks.sutdent_id
You should group on the student id and name and sum the marks:
SELECT s.id, s.name, SUM(e.marks) AS total
FROM student s
JOIN exam e ON s.id = e.stud_id
GROUP BY s.id, s.name
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Permission to ask, why is this the error? I try
select user_idea.idea_id,user_idea.title, idea_events.events, idea_categories.category_name AS category
from user_idea
LEFT join idea_events
on user_idea.idea_id=idea_events.idea_id
LEFT JOIN idea_categories
ON user_idea.idea_categories=idea_categories.category_id;
The result is sqliteonline like this:
I want to combine Dewasa and Anak events because of the same idea. For category why is the result NULL for values 1;2 not read in the idea_category table which should be Mudah; Sedang.
For table:
Output expected:
select user_idea.idea_id,user_idea.title,
(SELECT GROUP_CONCAT(events,';') FROM idea_events Where user_idea.idea_id=idea_events.idea_id) as events,
(SELECT GROUP_CONCAT(category_name ,';') FROM idea_categories Where user_idea.idea_categories=idea_categories.category_id) AS category
from user_idea;
1:2 idea_categories in user_idea is not considered as relevant to join so when joined it cannot find the data in other table here so data is null
reminder
before doing join just analyse the data anomalies like not having common data and properly formatted
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
List the name of all clients who have viewed a property based on the UML graph
SELECT [C-NAME]
FROM [CLIENT]
JOIN [PROPERTY]
ON CLIENT.CLIENTID = PROPERTY.PROPERTYID
If I've understood that UML model you can't, View-Appointment needs ClientID and PropertyID adding.
Then you can do, to give all clients that have an appointment (obviously adding a WHERE on the date column will give you future/past appointments):
select [C-Name] from [Client] inner join [View-Appointment] on Client.ClientID = View-Appointment.ClientID;
If you want property details in the query then you need another inner join:
inner join Property on Property.PropertyID = View-Appointment.PropertyID
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How can I write a SQL query that will replace the "ComputerID" and "PartID" with the "UnitNumber". The ComputerID's and PartID's are in the same column under InventoryID. The InventoryID's are unique but the UnitNumber (sticker label/name) doesn't have this requirement.
Here are the tables and how they relate.
Let's call your tables Object and Inventory
If you use a couple of joins then this should work:
select o.ObjectID as ObjectID, a.UnitNumber as Computer, b.UnitNumber as Part,
o.InputID from Object o
join Inventory a on a.InventoryID=o.CombputerID
join Inventory b on b.InventoryID=o.PartID