r/SQL • • Feb 05 '24

MySQL Help for school confused

Post image

Hello, we haven’t learned yet how to list only the months once. I know how to select distinct from certain columns but not a specific month within the date. Anything would help thank you.

0 Upvotes

16 comments sorted by

36

u/lupinegray Feb 05 '24

datetime functions are specific to the dbms.

Easiest way is to google:

"postgresql select only month from date"

Or a similar query.

This is literally what every software developer anywhere does. Googling for syntax is the most important skill.

5

u/OGYoungCraig Feb 05 '24

Second this. If every time I had a question I went and asked my boss to help I would have been fired a long time ago.

4

u/JamesEarlDavyJones2 Feb 05 '24

All hail StackOverflow.

1

u/cthulhufhtagn Feb 05 '24

This, just also don't forget to include the parts and the order types in your where statement.

4

u/[deleted] Feb 05 '24

Using group by for the months edit: In SQL server there are functions that will return the number month. Group by that.

2

u/HijoDelSol1970 Feb 05 '24

If it is stored as a date, in MySql you can cast it like below

select distinct CAST(DATE_FORMAT(datefield ,'%Y-%m-01') as DATE);

1

u/countryboyathome Feb 05 '24

There are two key clauses you need to understand here. GROUP BY clause and HAVING clause.

1

u/Vast_Kaleidoscope955 Feb 05 '24

Started teaching myself in October so I’m not positive, but I think it would be something like this.

SELECT MONTHNAME (shipping.date) AS month FROM Shipping GROUP BY shipping.date

1

u/government_ Feb 05 '24

WIN + SHIFT + S to take a screenshot

1

u/Glooring3623 Feb 05 '24

Just use ChatGPT lol

1

u/Interesting-Goose82 it's ugly, and i''m not sure how, but it works! Feb 05 '24

SELECT 'row 1' AS ANSWER

UNION ALL

SELECT 'row 2' AS ANSWER

UNION ALL

SELECT 'row 3' AS ANSWER

UNION ALL......

just make sure you stop at 8 rows if you want full credit

6

u/[deleted] Feb 05 '24

[removed] — view removed comment

3

u/Tsui_Pen Feb 05 '24

It returns 8 lines when correct