Skip to content

Tag: sql

How to use scalar variable in XML Path query SQL?

I want to pass table name into into a scalar variable @Table_Name as a string. But I am getting error as: Must declare the table variable @Table_Name. How to achieve the same? Below is my code snippet: Answer So I created a temporary table using the input provided by the user and used that temp table in the q…

Group by not getting the expected results in mysql

I have the next query: That is working perfectly and returning 9 rows: I want to group the results by boat type and get the number of boats per type. However, when I do: I´m getting: but according to the first query, I´m expecting What am I missing? Answer I suspect that you want: That is: move the DISTINCT w…

using condition for Group_Concat

I want to find all ids of which group_concat only contains ‘a’. Here is simplified table from mine. ╔════╦══════════════╦ ║ id ║ group_concat ║ ╠════╬══════════════╬ ║ 1 ║ a,b,b ║ ║ 2 ║ a …

php mssql next row

I need some advice how to get the next value of a row with while loop in php-mssql. same articles My code:

left join not working or maybe I don’t know how to use it

I’m trying to generate a query with left join. The idea is that I can get: Because I need only rows that have same columnA (job), with different columnB (bat). I’m trying with left join but it is not working. Could you help me why my sql sentence is wrong? Answer GROUPBY with COUNT() will get you …