r/SQL • u/Code_Ynot • Sep 13 '26
MySQL SQL should have coordinates by default
ynot? Why does SQL not have coordinates for it's tables?
like what if i want to see table 2 row 1 column 5 and have a command for just that.
No names required
0
Upvotes
4
u/Eleventhousand Sep 13 '26
If you wish to implement your own matrix, I would suggest doing it in a row-based methodology. For example, a column for row_id, a column for column_id, and a column for value. That way, you could reference coordinates in the where clause.
14
u/alinroc SQL Server DBA Sep 13 '26
SQL doesn't have "coordinates" because tables are not spreadsheets (BTW, you can name columns in most spreadsheets and reference them that way). It's not even a matter of "have by default" vs. "as an option" because it doesn't even exist "as an option."
A table in a relational database has no defined order; in a result set, this is even more evident as the ordering of results is never guaranteed without an explicit
ORDER BYclause. This renders your row "coordinate" invalid.Column positioning can change (most DBAs cringe at reordering columns because it's incredibly expensive), rendering your column "coordinate" invalid.
There are some RDBMSs and situations where it is possible to refer to a column by its ordinal position, but it's not what you're asking for here.
Row and column numbers are purely a construct in client applications for visual reference. Nothing more.
6
u/r3pr0b8 GROUP_CONCAT is da bomb Sep 13 '26
why not?
because tables aren't numbered, so table 2 makes no sense
because rows aren't numbered, so row 1 makes no sense
because columns aren't numbered, so column 5 makes no sense
your idea? it doesn't make any sense
4
u/ncmtbiker Sep 13 '26
A database table is not an Array. They are modeled after mathematical sets. So the rows have no guaranteed inherent order without an explicit ORDER BY clause.
The columns do have a defined position. This created when the table is designed. Which allows for order by 5, which will order by the 5th columns. This is VERY bad coding because a new column can be added anyplace in a table and would break your query.
4
u/feignapathy Sep 13 '26
There'd have to be some kind of ordering applied to the data. Otherwise, you're just pulling a random record or whatever.
And what exactly does that achieve?
2
u/RainbowFlesh Sep 13 '26
In what scenario would you ever want that?
1
u/TheLuminary Sep 13 '26
Why... Would you want that? What would you do if the column order changes. Or the table order changes?
Better to increase your specificity with table and column names. I don't see any reason why your idea of numeric access to database information would be preferable.
What would your use case be?