You may have been using subqueries to get how many rows were grouped when using MySQL’s GROUP BY function. There’s a little trick that helps to get this number without using subqueries, more clean and faster (when the amount of rows get higher). Let’s assume we have a table contain folks from different cities. Like […]
Tag: SQL
Generate DateTime Value in PHP for Using in MySQL Command
When we work with date and/or time values in MySQL, it’s always easy to use built-in MySQL functions such as NOW(), DATE_ADD(), TIMESTAMP() etc… Now imagine you have to pass date/time values to MySQL from PHP variables. First time I tried that, it didn’t work out so easy for me. Yes, if you simply take […]
T-SQL: Concatenate Multiple Rows of a Column into One Cell
Simple: You have a column and you want to take all rows as one cell. So that you can do searching, ordering, whatever you like. Solution: Declare a variable, in this case VARCHAR or NVARCHAR, then SELECT the variable by equaling [itself] plus [column name] plus [your seperation char]. Here’s the code snippet: