FAQ Database Discussion Community


Merge results from two separate columns into one elongated column

sql,oracle,select
My table: ID Name Status1 Status2 ------------------------------------- 1 foo bar grain 2 bar foo sball 3 foo bar grain 4 far boo sball I need for it to actually come out like this: ID Name Status ------------------------------- 1 foo bar 1 foo grain 2 bar foo 2 bar sball 3...

Cakephp3 transaction find query

mysql,select,transactions,cakephp-3.0
When making a transaction in cakephp3 and adding a get() query inside all works fine. But why is a find() query not performed inside the transaction? I have the following controller in cakephp3: <?php namespace App\Controller; use Cake\Core\Configure; use Cake\Network\Exception\NotFoundException; use Cake\View\Exception\MissingTemplateException; use Cake\Network\Session; use Cake\Event\Event; use Cake\Network\Http\Client; use Cake\ORM\TableRegistry;...

Formatting dates in PostgreSQL

sql,postgresql,select,date-formatting
I have a field which its format is date with time as: YYYY-MM-DD HH-MM-SS for example: 2000-08-12 00:00:00 I want to get just the date part and change its format to DD/MMM/YYYY for example the expected result of the previous example will be: 12/Aug/2000 The field definition is: Ddate timestamp...

Which performs first WHERE clause or JOIN clause

sql,sql-server,select,join,where
Which clause performs first in a SELECT statement? I have a doubt in select query on this basis. consider the below example SELECT * FROM #temp A INNER JOIN #temp B ON A.id = B.id INNER JOIN #temp C ON B.id = C.id WHERE A.Name = 'Acb' AND B.Name =...

referencing mySQL query components

mysql,sql,select,alias
Is there a way to make reference to parts of a MySQL query within the same query? For example: SELECT 50000 AS starting_principle, .065*50000 AS interest, principle + interest AS principle_plus_interest The third column, principle_plus_interest in the query set gives me an error. Is there a way to code this...

PHP $wpdb Select?

php,mysql,wordpress,select
I could use some assistance with an sql query. I have a small 3 column table, id, ip, and birthday. id auto increments. I'm trying to select all birthdays that are associated with a specific ip, but I'm not sure if the SQL statement I wrote is correct. The var_dump...

How to select the last 12 months in sql?

sql,sql-server,select
I need to select the last 12 months. As you can see on the picture, May occurs two times. But I only want it to occur once. And it needs to be the newest one. Plus, the table should stay in this structure, with the latest month on the bottom....

How to change multiple form elements via single select

html,forms,select,if-statement,onchange
I'm completely stumped at how I can change the opening tag to have 'method=post' if the second select option is chosen. I am using an Onchange for the form action, but can't figure out how to change the post method too. My latest attempt is with an IF statement as...

Mysql return only items that have n number of property matches

php,mysql,select,grouping
I have a database of items and each item has various number of properties. Is it possible for MySql only to return items that have a certain number of matches (not properties) when a search is run? Example: I am searching for any item with a wheel that is red...

SQL INSERT INTO WITH SELECT query

sql,sql-server,select,insert-into
Not being experienced with SQL, I was hoping someone could help me with this. I have a empty temp table, as well as a table with information in it. My outline of my query as it stands is as follows: CREATE TABLE [#Temp] (ID Int, Field1 Varchar) INSERT INTO [#Temp]...

How to select a range of my table

mysql,sql,select,range
I have a table like this: (Pay attention to the sequence numbers for every word) // tablename +---------+----------+ | word | number | ---------------------- | jack | 1 | | jack | 2 | | jack | 3 | | ali | 1 | | ali | 2 | |...

PHP: How to push Select results to multi-dimensional array (partially working)

php,arrays,loops,select,multidimensional-array
I am new to PHP and hope someone can help me with this. I have a Select query that returns (among others) the values from two columns in a db table, "ID" and "en". When getting the results from the Select I would like to store both these values for...

SQL Optimization: query table with different where clauses

sql,oracle,select,sql-optimization
I have the following SQL query: SELECT ( SELECT SUM(c1) FROM t2 WHERE t1.c1 = t2.c1 AND t2.c3 = 'NEW' AND t2.c4 = TRUNC(SYSDATE) AND t2.c5 = 'N' ) SUM, ( SELECT sum(c2) FROM t2 WHERE t1.c1 = t2.c1 AND t2.c3 = 'OLD' AND t2.c4 = TRUNC(SYSDATE) ) SUM2 FROM...

Understanding cartesian product in SQL

mysql,sql,select,join,cartesian-product
I am not able to understand how Cartesian product works. Consider the simple schema: mysql> select * from account; +----------------+-------------+---------+ | account_number | branch_name | balance | +----------------+-------------+---------+ | A101 | Downtown | 500 | | A102 | Perryridge | 400 | | A201 | Brighton | 900 | |...

how to Select data from multiple tables with several conditions?

sql,oracle,table,select
There are tables FACULTIES (F_NUMB, F_NAME, F_TELEF) and STUDENTS (S_NUM, SURNAME, SPECIALITY, GROUP, FACULTY_NUMB). Please write SQL query to achieve faculties names in which the count of students are greater than in faculty “Computer science”. This is what i'm doing: select faculties.f_name, count(STUDENTS.S_NUM) from STUDENTS, FACULTIES where students.fac_num=FACULTIES.F_NUMB group by...

Select where max date

sql,sql-server,select,max
I want to select the last note from notes with the following query: SELECT cn.Note, MAX(cn.Date) FROM CarsNote cn WHERE CustomerID = '80' AND cn.Type = 'INFO' GROUP BY Note When I execute this query i get four results but i want only the last note. When i do SELECT...

Javascript - return dynamic row data with checkbox input

javascript,forms,select,checkbox,tabular
I seem to only be able to find the answer to this problem in JQuery and I would really like a pure JS solution. I have a dynamically generated table that I build from a parsed JSON file. I added a checkbox for each row. My question is, do I...

How can I find get attribute of a select tag where value = something using jquery?

jquery,select,drop-down-menu,html-select
How can I get the price attribute's value where #products.option value = 6. <select id="products"> <option value="2" price="60.00">Product 1</option> <option value="4" price="40.00">Product 2</option> <option value="6" price="40.00">Product 2</option> <option value="8" price="40.00">Product 2</option> </select> ...

How to perform boolean addition on an SQL select

sql,sql-server,select,sum,boolean
I have the following data in a database table column named timeSchedule 00100110 00010100 00110000 00110011 Boolean addition would result in 00110111 Is there a way to do this in sql? Something like select sumboolean(timeSchedule) from myTable Someone asked for DDL+DML.. here is an example: CREATE TABLE [dbo].[myTable]( [musPracticeID] [int]...

SQL Select - Group by along with inner join?

sql-server,select,group-by,inner-join,distinct
I'm using the following query: SELECT TOP 12 INVENTABLE.ITEMNUMBER, INVENTABLE.ITEMNAME1, INVENTABLE.ITEMNAME2, INVENTABLE.W_TILBUD, INVENTABLE.COSTPRICE, INVENTABLE.VENDITEMNUMBER, INVENTABLE.A_PRODUCENT, INVENTABLE.GROUP_, INVENTABLE.A_GROSSISTLAGER, INVENTABLE.SupplementaryUnits FROM INVENTRANS INNER JOIN INVENTABLE ON INVENTABLE.ITEMNUMBER=INVENTRANS.ITEMNUMBER WHERE INVENTRANS.ACCOUNT='xxx' AND INVENTABLE.W_VISFORSIDE = 0 AND INVENTABLE.W_VISWWW = 1 AND INVENTABLE.BLOCKED = 0 ORDER BY INVENTRANS.ROWNUMBER DESC This query selects the 12...

Nested SQL statement with AVG()

php,mysql,select
I have three tables I want to pull data from. One is a classes table that stores a list of classes offered including an id, time stamp, trainer id, start time, am/pm and the days a class is held. The trainer id is a foreign key that ties it to...

JQuery select input value from input text generate by php

php,jquery,select
i have this structure that i generate for each element finded by a search <?php foreach ($this->pneumatici as $pneumatico) :?> <div class="col-md-3 element-form"> <div class="input-group input-float"> <input type="hidden" name="codice" value="<?= $pneumatico->codice ?>" id="codice"> <input type="text" class="form-control" id="quantita" value="0" size="1" maxlength="2" <?php if ($pneumatico->quantita == 0){ echo "disabled" } ?> >...

psql max group by just for some columns

sql,postgresql,select,max,psql
I have a problem in a psql query. I don't know how to select only the maximum value from a subset of two columns. It's very hard to explain the problem without an example, so I write one: I have a table like that: Athlete | Category | Points at1...

Knokout select : Set Selected Item by item name not value

jquery,select,knockout.js
i have a knockout select as following observable Array issuingCountries 0: ObjectCoordinatorRegion: "EU" Country: "Australia" CountryId: 14 Id: 1 2: ObjectCoordinatorRegion: "AU" Country: "Japan" CountryId: 16 Id: 2 html <select class="issuing_country" data-bind="options: issuingCountries, optionsText : 'Country', value:IssuingcountrySelected, optionsCaption:'---Select---', " > </select> My question , i have { Country: "Japan" }...

Selecting and removing a html select option without selecting by index or ID, using vanilla JavaScript

javascript,function,select,options
I need to remove an option on a select box, and I've figured out a potential solution in the code below, but it doesn't feel particularly 'safe' (if another developer decided to add an option to the backend, the option will re-appear). Is there a better way of achieving this...

SQL Select Statement - Column Ambiguously Defined even when defining which table each column comes from

mysql,sql,select
I'm doing a beginners course on SQL and databases, and I'm trying to write a select statement that will join two tables on Oracle Apex. I'm using join...on... to do so. The two tables each have a column named the same, with the columns filled with matching values. Obviously, they...

Pandas DataFrame: Delete specific date in all leap years

python,select,pandas,leap-year
The following sequence is an extract of the pandas DataFrame that I've got: >>> df_t value 2011-01-31 -5.575000 2011-03-31 7.700000 2011-05-31 15.966667 2011-07-31 10.683333 2011-08-31 10.454167 2011-10-31 9.320833 2011-12-31 -0.358333 2012-01-31 -11.550000 2012-03-31 1.700000 2012-05-31 12.333333 2012-07-31 12.816667 2012-08-31 11.837500 2012-10-31 2.733333 2012-12-31 4.075000 2013-01-31 2.450000 2013-03-31 -4.262500 2013-05-31 11.491667...

PHP: While loop not working after adjusting SELECT for SQL injection prevention

php,mysql,select,sql-injection,associative-array
I am trying to set up PHP queries for MySQL in a way to prevent SQL injection (standard website). I had a couple of INSERT queries where changing this worked well but on the following SELECT I keep getting an error since the update and it looks like the while...

is it possible select the hit field of the search query

mysql,sql,select
I need to search on both from_a and from_alt fields, but should select only the hit field(field which matches with search criteria) as from_airport sample table : +--------+-----------------+ | from_a | from_alt | +--------+-----------------+ | FRA | BER,MUQ | | JFK | CAL,FRA | +--------+-----------------+ sample query for normal selection:...

SQL Server query syntax with single quote

sql,sql-server,sql-server-2008,select,escaping
I have in my database KIA car model like CEE'D. How to write right syntax to get all car where model = CEE'D Now I am using semipart of model SELECT make, model FROM Cars WHERE model LIKE '%CEE%' But now I need to get by full model name. How...

I am using a select in form field. data is inserted properly but displayed id only instead of text

laravel,select
Create page <div class="form-group"> <label><b>STATUS</b></label> {!! Form::select('status', ['Draft','Published']) !!} </div> Index page @foreach($sliders as $slider) <tr> <td>{!! $slider->id !!}</a></td> <td>{!! $slider->status !!}</td> @endforeach Controller public function store(Slider $slider,CreateSliderRequest $request) { // $slider=$slider->lists('name','id'); $slider = $slider->create($request->all()); Session::flash('message', 'The...

Selecting multiple values from a single LINQ Query

c#,linq,select
I am having issues selecting multiple values from a LINQ query. I Can actually get the results I am looking for but it's not how I would like it.. This is my query. var getMovie = from item in entList where item.EType() == "Movie" orderby item.Rating select new { item.Title,...

How to see the table just modified in a script with Sql Developer

sql,oracle,select,plsql,oracle-sqldeveloper
I've this block in sql developer: begin delete from temp; insert into temp values (1); dbms_output.put_line('Done'); end; If I hit F5 the script runs fine. The table is updated with the value 1 and the "Script output" tab says 'Done'. However I would like to automatically visualize the table that...

Condition on resultset of a select that return null or not null values-Java

java,sql,select,null
For an application,I am checking if a table is filled so that I can retrieve that from it; otherwise I will retrive from another table. For that, I use a select and checks if it has null values by wasnull(). If it does, I execute a query; otherwise, I execute...

Using Sum in If in Mysql

mysql,sql,select,sum
I want to select the sum of values of my_field. The unit of my_field is in seconds. I don't want to exceed 24 hours, so when it exceeds 24 hours, I want it to select 24*60*60 = 86400. SELECT IF(SUM(my_field) > 86400, 86400, SUM(my_field)) ... This solution doesn't seem to...

change the content of a select option

jquery,forms,select,text,options
I'd like to change the text shown in a select form, without changing the HTML elements. This is an example: <select class="myclass" name="myselect"> <option value="0">1</option> <option value="1">2</option> </select> I would like to change the "2" string into "TWO", for example, like: <option value="1">TWO</option> I'm not able to select the right...

Autoupdating Field Based on two