Closed Thread Icon

Topic awaiting preservation: SQL pro (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=22290" title="Pages that link to Topic awaiting preservation: SQL pro (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: SQL pro <span class="small">(Page 1 of 1)</span>\

 
Hiroki
Paranoid (IV) Inmate

From: NZ to Japan
Insane since: Dec 2002

posted posted 06-23-2004 07:33

Hi, guys. I have got a sql question. Please help me.

Here is data
col0, ID, col1, col2
----------------
1, a, 100, 0
2, a, 101, 0
3, a, 102, 0
4, b, 200, 0
5, b, 201, 0
6, b, 202, 1
7, c, 300, 0
8, c, 301, 0
9, c, 302, 0
-----------------

I want to extract all b. When each ID gets col2, which is "1", I want to show all data of that ID.
Hum..... Make sence????

In the case above, I want to show like below
------------------
b, 200
b, 201
b, 202
------------------

Not only
-----------------
b, 201
-----------------

Please help me.

Hiroki Kozai

(Edited by Hiroki on 06-23-2004 07:38)

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 06-23-2004 07:53

SELECT ID,col1 FROM table_name WHERE ID = 'b' ???

I am having some trouble understanding what exactly you are asking for. That matches your pattern. If you could clarify gramatically what you are trying to do I am sure I could be of some more help.

Hiroki
Paranoid (IV) Inmate

From: NZ to Japan
Insane since: Dec 2002

posted posted 06-23-2004 08:03

Hi, thanks for your help.
Well, in my case, I have to check col2 if it is 1 or not. Then if col2 is 1, I want to show all the data of that ID's data.

For example,
----------------
1, a, 100, 0
2, a, 101, 0
3, a, 102, 0
4, b, 200, 0
5, b, 201, 0
6, b, 202, 1
7, c, 300, 0
8, c, 301, 0
9, c, 302, 0
10, d, 401, 0
11, d, 402, 0
12, d, 403, 1
-----------------

This case, I want to show below cuz b and c has col2,which is 1
-----------------
b, 200
b, 201
b, 202
d, 401
d, 402
d, 403
-----------------

many thanks in advance.
Cheers.

Becasue

Hiroki Kozai

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 06-24-2004 02:57

Hiroki

In reading your explaination, it's still hard to understand what you're trying to do. You say you want to select those rows that have a col2 value of 1. In looking at your sample data only 2 enrtys match that:

b, 202
d, 403

but your showing 6 entries that you really want returned.

Can you try to clairify it yet a little more?

-Butcher-

(Edited by butcher on 06-24-2004 02:58)

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana, USA
Insane since: Aug 2000

posted posted 06-24-2004 17:48

My SQL is a little rusty, but I think your trying to do something like

code:
SELECT ID,col1 FROM table_name WHERE ID in select ID from table_name where id = 1



-- not necessarily stoned... just beautiful.


(Edited by hyperbole on 06-24-2004 17:56)

Hiroki
Paranoid (IV) Inmate

From: Japan
Insane since: Dec 2002

posted posted 06-25-2004 03:54

Hi, guys. many thanks for your reply and sorry for my poor explanation.
hyperbole:
Yeah, it is what I wanted.
I could not understand 'in select'
I got the result right, but would you explain what in select do???
Again, many thanks for your replies.
I have been absent from this site for a while, but still keep doing this kind of things.
Cya.

Hiroki Kozai

« BackwardsOnwards »

Show Forum Drop Down Menu