Help with SQL code

Hi there,

i have this table

i run this query:

SELECT *
FROM pippo
WHERE B like 'XX'
UNION
SELECT *
FROM pippo
WHERE E like 'XX'

because i want only the record that contain "XX" (the column A,B,C,D,E,F must remain) but the query output return even a record with "YY"!

Can someone help me???

Thanks

This

Thanks

Ok this is a great method but my table was an example, i have in a real world a table with 100 or more records and i need a quick method to search "XX" or something like this. I can't create every time a new table and put NULL in every record!

ok thanks i try to explain better

in this table column A,G,D,L are equal;

if i want to search "XX" as output only the records that contain "XX"

i hope i was clear!

Thanks a lot!

you could write something like:

select * from pippo where 'xx' in (a,b,c,d,e)

I obtain the same output and the record with "YY" remains!

select * from pippo where 'xx' in (a,b,c,d,e)
except 
select * from pippo where 'yy' in (a,b,c,d,e)

This is not clear...

It sounds like you want to associate columns A,B,C as one record - then D,E,F as a second record, G,H,{D?} as a third record and L,M,N as a fourth record.

If you really have a table setup with 'repeating' segments of 'records', you really need to reconsider the design.

To get what I think you are asking:

SELECT A, B, C FROM pippo WHERE B = 'XX'
UNION ALL
SELECT D,E,F FROM pippo WHERE E = 'XX'
UNION ALL
SELECT G,H,{D?} FROM pippo WHERE H = 'XX'
UNION ALL
SELECT L,M,N FROM pippo WHERE M = 'XX'

If this is correct - you really have to redesign your 'table' and normalize the data.

Yes i arrived at the same point. Thnaks for your help