Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple APILearn More
Congrats on your achievement 😀
Small advice, don't do SELECT *
But instead use column names, because in production software using column names helps in:
1. Reducing amount of data read from DB
2. Assuming column name changed or even entire column is dropped error is detecged from database level
3. Using columns instead of SELECT *
Itwill give reader an idea of why this query was written instead of having to read code afterwards to find out
cannonau2122yI got distracted and only read "I couldn't wait to make one/learn basic" and I was like wut
taglia6172y@C0D4 "select a.* from a join b on .." and the problem is gone.
For its use, it depends. If I only need 2/3, I get them by name, otherwise "*".
@gitpush well, technically you'll need to check what they are doing with the results of the query anyway, so having 4 called by name or everyone doesn't make a big difference. In the end, I think it is just a matter of taste..
The * has it's use.
If you are joining tables you should use (and need to) use the table alias.
You can join several tables and just use database.table.* to get everything from the database.table
The part where it becomes important to select specific fields is mostly in regards to data type and data type handling.
If you have eg mostly numeric data inside the table it might not be relevant - but blob / text and other binary storage might lead to an performance impact...
- due to the way it's stored (eg in MySQL InnoDB outside the "main table data" )
- due to it's size - eg. one utf8 char has 4 byte or for binary storage in most cases it's stored in chunks / inodes… leading to Overhead
- both cases might influence the query plan
And.... To end it.
COUNT(*) is on a table with a PK in all cases faster than COUNT(columnName) in MySQL.
So. * is not evil per se. Just think about wether you make the database give you necessary information or If you make it.... Vomit.
Root728742ySQL is a breeze to learn.
It's also a breeze to write terrible, inefficient queries.
linuxxx103It was between me and another guy. I fucking won! I GOT THE FUCKING JOB!! I'll be a junior Linux Support...
dfox6If you're not learning anything new at your job it's probably time to move on.
yansch11Manager: "we need an SQL database" Dev: dude does he even know what he's talking about Dev: "so which color?" ...