SQLTeam.com | Weblogs | Forums

Selecting all columns


#1

I am just learning SQL and working with a MySQL database. My Database has 10 columns: prim, Date, num1, num2, num3, num4, num5, num6, num7, bonus. It is a lotto database. I am trying to make a query that calls the most called numbers and bonus. My current work is:

SELECT * FROM draws WHERE num1, num2, ... this, however, is not giving me what I want. I have been reading through Tutorialpoint on Mysql database but it is no help when it comes to selecting a range of columns. Is this even possible to select a range of columns or am I doing it wrong?


#2

I am not familiar with MySQL but using TSQL.
SELECT num,COUNT() AS cnt
FROM (
SELECT num1 AS num
FROM TABLE
UNION ALL
SELECT num2
FROM TABLE
UNION ALL
SELECT num3
FROM TABLE
UNION ALL
SELECT num4
FROM TABLE) Z
GROUP BY NUM
ORDER BY COUNT(
) DESC

-- I havn't put all the columns it but it gives you the idea.
-- PS If you win.. I want half :slight_smile: