SQL Query Multiple Columns Using Distinct on One Column Only
select * from tblFruit where tblFruit_ID in (Select max(tblFruit_ID) FROM tblFruit group by tblFruit_FruitType)
select * from tblFruit where tblFruit_ID in (Select max(tblFruit_ID) FROM tblFruit group by tblFruit_FruitType)
<select id=”ddlViewBy”> <option value=”value”>text</option> </select> JQuery var txt = $(“#ddlViewBy option:selected”).text(); var val = $(“#ddlViewBy option:selected”).val(); JS Fiddle DEMO
wrap the value with single quote and surely it will work SELECT * FROM ctx_bookings WHERE DATE(booking_time) <= ‘2012-12-28’ ORDER BY id ASC SQLFiddle Demo
You can do it like this: Fiddle demo declare @results varchar(500) select @results = coalesce(@results + ‘,’, ”) + convert(varchar(12),col) from t order by col select @results as results | RESULTS | ———– | 1,3,5,9 |
DISTINCT is not a function that applies only to some columns. It’s a query modifier that applies to all columns in the select-list. That is, DISTINCT reduces rows only if all columns are identical to the columns of another row. DISTINCT must follow immediately after SELECT (along with other query modifiers, like SQL_CALC_FOUND_ROWS). Then following … Read more
You don’t use the VALUES keyword when inserting from a SELECT statement. INSERT INTO t2 (a, b) SELECT a, b FROM `t1` AS o WHERE o.id NOT IN ( SELECT a FROM t2 )
If you are using MySQL 8, the preferable solution would make use of the window functions FIRST_VALUE() and/or LAST_VALUE(), which are now available. Please have a look at Lukas Eder’s answer. But if you’re using an older version of MySQL, those functions are not supported. You have to simulate them using some kind of workarounds, … Read more
DATE_ADD works just fine with different months. The problem is that you are adding six months to 2001-01-01 and July 1st is supposed to be there. This is what you want to do: SELECT * FROM mydb WHERE creationdate BETWEEN “2011-01-01” AND DATE_ADD(“2011-01-01”, INTERVAL 6 MONTH) – INTERVAL 1 DAY GROUP BY MONTH(creationdate) OR SELECT … Read more
select T.Column1, T.Column2, T.Column3, T.Column4, ( select count(*) from (values (T.Column1), (T.Column2), (T.Column3), (T.Column4)) as v(col) where v.col is not null ) as Column5 from Table1 as T
this would do: $(‘#selectId’).html(”);