views:

131

answers:

3

Hi guys. I will re-write my doubt to be more easy to understand. I have one table named SeqNumbers that have only one collumn of data named PossibleNumbers, that has value from 1 to 10.000. Then I have another Table named Terminals and one of the collumns have the serial numbers of the terminals. What I want is get all the SerialNumbers that not exists in the Terminals table from 1 to 10.000. I've created the SeqNumbers table only to do this... maybe there's another solution without using it... that's fine to me. The query I have is:

SELECT PossibleNumbers from SeqNumbers Where PossibleNumbers NOT IN (SELECT SerialNumbers from Terminals)

Basically I want to list ALL serial numbers of terminals that doesn't exists in the database. This Query works fine I think... but the problem is that I don't want all results in a single collumn.. I want these results displayed in 4 or 5 collumns. For my porpuse I can only use the results from the query like that. I cannot use programmatically methods to do that... :( :(

Hope this is more clear now... Thanks for all the help...

+2  A: 
select x, x+1000  from tablename

Will that do it for you?

Rap
Sorry for downvote, because I know the question changed on you. But this is not what he wants and we need to get a better answer voted above this one.
Joel Coehoorn
Sorry ... that wouldn't do what I wanted. thanks anyway
Carlos
A: 

You can use a scripting language to parse the MySQL results to format it anyway you like. Are you using PHP to access the database? If so, let me know and I can cook one up for you.

I just saw your new updated question. In this case the order of the columns will be ordered by your SELECT statement and you can also sort too. Here is an example:

SELECT Column1, Column2 FROM my_table ORDER BY Column1, Column2 ASC
Knix
No I'm not using PHP. I just want to make a query in the SQL Server to get the results... I have explained better what I want in the answer of Chris Shaffer.Thanks guys for all the help... this is a odd query for me and I really need it.
Carlos
+2  A: 

If I'm reading this right, you'd probably have to do a self join; something like:

SELECT
   LeftValues.ColA,
   RightValues.ColA AS ColB
FROM YourTable LeftValues
    LEFT JOIN YourTable RightValues ON LeftValues.ColA = RightValues.ColA - 1000
WHERE LeftValues.ColA < 1000

Note: Use the JOIN that makes sense for you (left if you are willing to accept NULLs in ColB, inner if you only want them where both values exist)

Chris Shaffer
I don't understand your query... I will describe exactly what I want maybe I have not been clear... sorry.I have one table TabA that I'd created with a single collumn with numbers from 1 to 10.000. I have another table TabB with some data and one of the collumns are serial numbers os products. I want to know all the serial number that DOESN'T exist in that TabB from 1 to 10.000. I already made that query with IS NOT in... but I get all results in one single collumn. Now I want to separate this results by multiple collumns. Imagine, 100 for each one for example. 5 ou 6 collumns would be nice.
Carlos
So it sounds like what you are wanting is entirely for display purposes and that the ColA and ColB values have no correlation? My query is based on the assumption that the values are mathematically correlated (eg, colA = ColB - 1000). While a non-correlated solution is possible in SQL, it probably will not be the best approach; You probably should return the query to some application as is and let that application display it however you need it to. If a SQL solution is required, update your question to include more detail/better example and tags to include your SQL dialect.
Chris Shaffer
Hi Chris, I updated my question .. may be you can understand it better now. I cannot use another application to do the job.. i really have to have multiple collumns with the results.. and as you can see now there is no mathematical correlation between the numbers... Hope you can help. Thanks a lot
Carlos