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 9 years ago.
Improve this question
I'm stuck at one of my homework assignment.
The question was:
Which l.levcode's are not in b.levcode's?
This is how far I got:
SELECT l.levcode, levnaam, levadres, levwoonplaats
from leverancier l, bestelling b
where l.levcode = b.levcode
but now I don't have a clue what to do.
try this code:
SELECT l.levcode, levnaam, levadres, levwoonplaats
from leverancier l
where l.levcode not in
(select levcode from bestelling)
You can simply use NOT IN
SELECT l.levcode,
levnaam,
levadres,
levwoonplaats
FROM leverancier l
WHERE l.levcode NOT IN (SELECT b.levcode
FROM bestelling b)
I think this should work:
SELECT l.levcode, levnaam, levadres, levwoonplaats from leverancier l, bestelling b where l.levcode NOT IN (select levcode from bestelling );
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 2 years ago.
Improve this question
I need to know record where ParentSpecID = to ChildSpecID cannot think of how to approach
It seems very simple using inner join, if I followed you correctly.
Select p.*, c.*
From parentspecid p
Join itemspecfullstruc i on i.rootitemspecid = p.itemspecid
Join childspecid c on i.childitemspecid = c.itemspecid
Where p.itemspecid = c.itemspecid
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
I have this data:
I'm looking for a query which can return the results of combination of Type (Phone and Memory) based on overlapping of startdate and enddate as below:
Thanks
Probably something like this:
SELECT *
FROM
table p
INNER JOIN
table m
ON
NOT(m.startdate > p.enddate OR m.enddate < p.startdate)
WHERE
p.Type = 'Phone' AND
m.Type = 'Memory'
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
i am trying to join these two tables, but I can only do so if I change values of columns while joining like "substr(to_char(p.personnummer),3)" and "substr(k.ip_id,1,10)" . Can anyone tell me what is the order I am supposed to do it?
select x.ip_id, x.organisationsnummer
from (select
substr(to_char(p.personnummer),3) as ip_id_jnr,
substr(k.ip_id,1,10) as ipo_id
from customer k
inner join customer_VIEW p on ipo_id = ip_id_jnr) x
;
Your query doesn't show which table contains organisationsnummer; I used the k alias (as if it belongs to customer); fix it if necessary.
So, inline view:
select k.organisationsnummer,
k.ip_id
from customer k join customer_view p
on substr(to_char(p.personnummer),3) = substr(k.ip_id,1,10);
Now use it:
select x.ip_id,
x.organisationsnummer
from (select k.organisationsnummer,
k.ip_id
from customer k join customer_view p
on substr(to_char(p.personnummer),3) = substr(k.ip_id,1,10)
) x;
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
Everyone. I am facing a problem. I have a query like following:
SELECT MAX(SUBSTRING(account_code ,5,3 )) as first_level_code
FROM acc_coa
WHERE category = '1';
Which work fine but now I need to get with full column values. I am attempting this way but not work.
SELECT account_code, MAX(SUBSTRING(account_code ,5,3 )) as first_level_code
FROM acc_coa
WHERE category = '1'
How can i achieve this?
Thanks in advance.
use subselect
SELECT account_code, SUBSTRING(account_code ,5,3 ) as first_level_code
from FROM acc_coa
where SUBSTRING(account_code ,5,3 ) = (SELECT MAX(SUBSTRING(account_code ,5,3 )) as first_level_code
FROM acc_coa
WHERE category = '1') ;
Add group by account_code at end of query
Use ORDER BY and a way of getting one row:
SELECT c.*, SUBSTRING(account_code, 5, 3) as first_level_code
FROM acc_coa c
WHERE category = '1'
ORDER BY SUBSTRING(account_code, 5, 3) DESC
FETCH FIRST 1 ROW ONLY;
Note: FETCH FIRST 1 ROW ONLY is the ANSI-standard mechanism for getting one row. Some databases use LIMIT or TOP or other mechanisms.
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 9 years ago.
Improve this question
I have 3 tables:
user(use_id, use_role),
message(mes_id, from_use_id[fk->user.use_id], mes_create_at),
message_user(mes_use_id, mes_id[fk->message.mes_id], to_use_id[fk->user.use_id])
User can be use_role=1(student) or use_role=2(teacher).
I have to get all Users that are use_type=1(student) sorted by last contact with teacher. No matter if student write to teacher or teacher write to student.
I assume you use ms sql:
select *
from
(
select student.use_id, Message.mes_create_at, Message.from_use_id, Message_User.to_use_id
from User student
join Message on Message.use_id = student.use_id and student.use_role = 1
join Message_User on Message_User.mes_id = Message.mes_id
where Message_User.to_use_id in (select use_id from User where use_role = 2)
union
select Message_User.to_use_id, Message.mes_create_at, Message.from_use_id, Message_User.to_use_id
from User teacher
join Message on Message.use_id = teacher.use_id and teacher.use_role = 2
join Message_User on Message_User.mes_id = Message.mes_id
where Message_User.to_use_id in (select use_id from User where use_role = 1)
) as temp
order by mes_create_at desc