473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Problem with some SQL queries

I have several questions about queries I make into my database. I will
explain you. Could you please help me?

1)In my people table, persons have a title (Mr, Miss, or whatever).

" select distinct person, title from people where title is null or
title is not null "

give:

PERSON TITLE
0000029 Miss
0000465 Mr
0000469 <-- null
0000624 <-- null
0000900 Miss

But when I calculate the number of titles (a lot of possibles types),
the title = null is not took into account. For that, I use " select
count(distinct title) from people where title is null or title is not
null ". How to make it successful?

2)Parameter between ' characters

My query is:

select distinct people.surname, people.forenames, sessions.stage,
sessions.course,
(select distinct title from shared.courses
where sessions.course=shared.courses.course) as titleofcourse
from people, sessions
where people.person=sessions.student and sessions.status='C'

I get:

SURNAME FORENAMES STAGE COURSE TITLEOFCOURSE
Aggett Stephen Peter James 2 V700 Philosophy <--
'Philosophy'

How to put the title of course (getting with a select) between '
characters?
I try without succes to use case or decode(). Have you got an idea?

3)A query on a same table

My people table is as following:

PERSON SURNAME FORENAMES TITLE KNOWNAS USERNAME EMAIL

I would like to check if there is any duplicates, ie two people with
the same surname and the same forenames.

I don't want to use a view containing the people table. I think it is
better to make it in a single query. Any idea please?

Something like " select * from people as p, people as pp where
p.surname=pp.surname " but which works?

Maybe it is something as:
"select p.surname, p.forenames
from people p, (select pp.surname, pp.forenames from people pp)
where p.surname = pp.surname and p.forenames = pp.forenames "
Jul 19 '05 #1
1 1970
Vince wrote:

1)In my people table, persons have a title (Mr, Miss, or whatever).

" select distinct person, title from people where title is null or
title is not null "

give:

PERSON TITLE
0000029 Miss
0000465 Mr
0000469 <-- null
0000624 <-- null
0000900 Miss

But when I calculate the number of titles (a lot of possibles types),
the title = null is not took into account. For that, I use " select
count(distinct title) from people where title is null or title is not
null ". How to make it successful?
Nulls have no defined value - not even 'nothing'. Therefore they can
not be counted. To work around this, assign a value to replace the null
using a function like NVL (although you really want to look it up to
make sure you are using the right function) OR count a non-null column
or pseudo-column such as rowid.

2)Parameter between ' characters

My query is:

select distinct people.surname, people.forenames, sessions.stage,
sessions.course,
(select distinct title from shared.courses
where sessions.course=shared.courses.course) as titleofcourse
from people, sessions
where people.person=sessions.student and sessions.status='C'

I get:

SURNAME FORENAMES STAGE COURSE TITLEOFCOURSE
Aggett Stephen Peter James 2 V700 Philosophy <--
'Philosophy'

How to put the title of course (getting with a select) between '
characters?
I try without succes to use case or decode(). Have you got an idea?

Lean about the CONCAT operator.
3)A query on a same table

My people table is as following:

PERSON SURNAME FORENAMES TITLE KNOWNAS USERNAME EMAIL

I would like to check if there is any duplicates, ie two people with
the same surname and the same forenames.

I don't want to use a view containing the people table. I think it is
better to make it in a single query. Any idea please?

Something like " select * from people as p, people as pp where
p.surname=pp.surname " but which works?

Maybe it is something as:
"select p.surname, p.forenames
from people p, (select pp.surname, pp.forenames from people pp)
where p.surname = pp.surname and p.forenames = pp.forenames "


Think about using a grouping-count and eliminate the non-duplicate rows
using a 'having' clause.

HTH
/Hans
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: christopher_mouse | last post by:
I have a split Access 97 database that I've been asked to secure. The data is sensitive and users include programmers who are routinely accessing the data directly, so I plan to remove all...
10
by: Saso Zagoranski | last post by:
hi, this is not actually a C# problem but since this is the only newsgroup I follow I decided to post my question here (please tell me where to post this next time if you think this post...
20
by: Development - multi.art.studio | last post by:
Hello everyone, i just upgraded my old postgres-database from version 7.1 to 7.4.2. i dumped out my 7.1 database (with pg_dump from 7.1) as an sql-file with copy-commands and to one file using...
1
by: loosecannon_1 | last post by:
Hello everyone, I am hoping someone can help me with this problem. I will say up front that I am not a SQL Server DBA, I am a developer. I have an application that sends about 25 simultaneous...
7
by: Salvador | last post by:
Hi, I am using WMI to gather information about different computers (using win2K and win 2K3), checking common classes and also WMI load balance. My application runs every 1 minute and reports...
0
by: kkrizl | last post by:
I've tried to research this problem, and I haven't been able to find any references to it. Probably because I shouldn't be doing it, but it was working, and now it's not. I'm trying to develop a...
1
by: kkrizl | last post by:
I've tried to research this problem, and I haven't been able to find any references to it. Probably because I shouldn't be doing it, but it was working, and now it's not. I'm trying to develop a...
29
by: wizofaus | last post by:
I previously posted about a problem where it seemed that changing the case of the word "BY" in a SELECT query was causing it to run much much faster. Now I've hit the same thing again, where...
9
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just...
1
by: eblackmo | last post by:
I have a test network consisting of four servers running windows 2003 server R2 SP2. I have set up a domain which functioned correctly for about a day and a half until the other servers decided they...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.