Most voted "sql" questions
Structured Query Language (SQL) is a language to query databases. Questions should include examples of table code and structure. This tag refers to the default language, not to be used for questions about the implementation of specific DBMS (such as Mysql, Postgresql, Oracle, MS SQL Server). In this case use the specific DBMS tag. Answers to questions marked with ANSI SQL should use SQL as much as possible.
Learn more…6,771 questions
Sort by count of
-
0
votes1
answer207
viewsI cannot enter the Datetime fields in the sql database
I can’t enter in the fields dateCreation and dataRefMovimento in the sql database private Contexto contexto; public void Inserir(RegCabecalho regCabecalho) { var strQuery = ""; strQuery += " INSERT…
-
0
votes2
answers1056
viewsQuery for MYSQL with IF to validate several table fields
I am developing a Property Classifieds, so I need to filter some fields if the internet user wants, such as: Number of rooms, Number of parking spaces, Number of bathrooms, etc. I need Query to have…
sqlasked 8 years, 8 months ago Gladison Neuza Perosini 861 -
0
votes1
answer266
viewsSELECT of 2 FK in the same table
In view of this scenario: Imagine a scenario in the field of oceanography, where the table_A , in addition to the primary key, also needs to keep the direction of the wind (dir_wind) and the…
-
0
votes1
answer43
viewsPrevious Record Search (Mileage)
I am trying to put together a report for supply management. I have a Supply Table with the following fields: DataAbastecimento, CódigoVeiculo, KmAbastecimento, Quantidade, Valor In the Report I’m…
-
0
votes2
answers200
viewsHow to select the foreign key id in the main table?
public List Select() { List ListaCaminhao = new List(); SqlConnection conexao = new SqlConnection(strCon); string sql = "Select * from Caminhao;"; SqlCommand cmd = new SqlCommand(sql, conexao);…
-
0
votes1
answer83
viewsReturn Date data according to month
I developed the following function: public function get_agendas() { $this->db->select("*, EXTRACT(MONTH FROM data) as mes_referencia, count(id) as total_registros");…
-
0
votes1
answer224
viewsTotal SQL Records in all columns
I need to return the total query records in a column, even repeated, like this: However, the query is kind of boring. A query of 106 lines, with several SUM() and with a mandatory ORDER BY. I cannot…
-
0
votes1
answer129
viewsColumn type for support table
I have a client table and would like to create a support table to avoid creating many columns (address, phone, phone1, email, Email1, Email2, car plate, mother’s name, etc.). The support table…
-
0
votes1
answer65
viewsSQL in propagated data
I need to hit the SQL below for the database Oracle. The idea is to retrieve the code from the table Produto associated with the table code Matriz. In this structure, the Matriz is related to at…
-
0
votes0
answers65
viewsCalculation in Excel and PHP/SQL with different result
I made the calculation of a column in my spreadsheet and the value is X. However, when I calculate the column with SQL using SUM, or even in a loop with PHP, the value is different. The funny thing…
-
0
votes2
answers216
viewsSort the largest on request
Good evening, I’m using the following command: select cliente_id, desconto, pedidos_detalhes.pedido_id, cliente_tipo from pedidos_detalhes inner join pedidos on pedidos_detalhes.pedido_id =…
-
0
votes1
answer316
viewsEmpty string return - Oracle
I have a table with a string and several fields separated by | (pipe) I need to bring each field in a column. I even got a way, the problem is that when a record does not have the field filled the…
-
0
votes2
answers336
viewsHow to update records marked with checkbox at a while
I am not being able to update the fields that are only selected by CHECKBOX, which I was able to develop right below: BD.SQL CREATE DATABASE IF NOT EXISTS `seq_acessos` DEFAULT CHARACTER SET utf8…
-
0
votes1
answer959
viewsHow to select all columns in the database
How to select all columns in the database with the names 'name' and 'date' I have the code <?php $sql = "??"; if ($rs = $bd->query($sql)) { while ($row = $rs->fetch_assoc()) { echo…
-
0
votes1
answer126
viewsForeign key SQL SET NULL
Well folks, let’s have one more question from me, I hope you can help me. I have the following problem: When I create a foreign key linking to another field of another table I always define it as…
-
0
votes1
answer302
viewsFriends System with PHP
Hello, I would like to know how to create a system of friendships for my application, facebook style. I’m not making a social network, but I need to implement this system. I have a table of users…
-
0
votes0
answers54
viewsInsert data by PHP
After submitting the form I do the following: $n_processo = $_POST['n_processo']; $nome = $_POST['nome']; $dia = $_POST['dia']; $mes=$_POST['mes']; $ano = $_POST['ano']; $data =…
-
0
votes2
answers56
viewsBest way to capture data from a query
I have presented in a table of a site information of a database this way: <? $sql = mysql_query("SELECT id, nome FROM pessoas"); //---------------DADOS------------------------ while($row =…
-
0
votes1
answer178
viewsSQL allocate record (Rowlock)
I am developing an application, and I am facing a problem about competition of records. What happens is that I have several people who can access the same record, so I needed that when a user clicks…
-
0
votes1
answer82
viewsCheck for UK before creating a
I have the following query: alter table FINALIDADE_OPERACAO_MODAL add constraint UK_t127pwh154arjh5whq0g4dlrm unique (NOME); As I create a function that checks if it exists before, and if it does…
-
0
votes1
answer1199
viewsUse FULL JOIN in Mysql
I needed to make a query that I return in a row the data of a candidate plus the courses to which I applied, and this data is in a relational table 'tblcandidatoCurso'. After some research I tried…
-
0
votes1
answer4399
viewsSQL Server query SQL with COUNT and INNER JOIN
I have a page in PHP where I have to return data from two tables that are in a database SQL Server. One of the banks is registered sellers and the other is of the categories where they are…
-
0
votes1
answer76
viewsPHP Fatal error: Call to a Member Function initBD() on a non-object
Hello I have the following php code function updateRecord($email, $score){ $sql = "UPDATE record set record = $score where email = '$email' "; $banco-> initBD()->exec($sql); //O Log indica o…
-
0
votes1
answer186
viewsError while writing data from some tables via application
I have an application in Asp.net mvc that, among other functions, registers personal data of customers. We recently switched the database access from one server to another, which has a copy of the…
-
0
votes1
answer48
viewsSelect turning different records into single
I need to make a select by unifying two different rows into one, with two new columns. I am using bd oracle and there is no possibility to update the tables. Example:…
-
0
votes1
answer851
viewsModeling for student attendance
I have doubts about the structure of the database for a frequency system. I thought of two structures and when doing a search I saw that both exist and are used in different systems. 1 - The first I…
-
0
votes1
answer584
views -
0
votes2
answers81
viewsView data from a database in modals
I made a table to display 2 database data, and then on each line put an icon so that when clicked there appeared a modal with information from that line of type: <? $sql = mysql_query("SELECT…
-
0
votes1
answer496
viewsproblems running createNativeQuery
Hello, everyone. I am creating a project that handles user registration. In this project there will be several types of users. To simplify, let’s call the types 1, 2 and 3. Depending on the type of…
-
0
votes2
answers455
viewsHow to delete the first ten records from a table when reaching a certain number of Rows?
Good evening, I have an SQL table in which I will put movie recommendations by users, but I want when it reaches a total of records in this table, it deletes the older records. My code is like this:…
-
0
votes1
answer119
viewsHow to delete record from 2 tables where one contains the left 0 SQL SERVER
I have 2 tables in which one is inserted the records that comes from a file txt and the other the records that comes from a file excel. With this, I need to delete the records from the table txt…
-
0
votes0
answers63
viewsHow popular is Jtable?
I have to fill out a table with bank data. But nothing appears at all. My Class Inserting information in the table: DefaultTableModel dtm = new DefaultTableModel(); String sql = "select * from…
-
0
votes1
answer42
viewsSyntax of Mysql
I can’t see the error: UPDATE clientes SET txtEndereco=\"Rua Xingú, 823\", txtBairro=\"Val ParaÃso\", txtCEP=\"09060-050\", txtUF=\"35\", txtCidade=\"14933\", regiaos=\"\", Obs=\"Princesa fada\")…
-
0
votes2
answers150
viewsIs this kind of normalization feasible?
From here you will have more tables where the person will classify as, owner, customer, supplier, among others. My question is, by separating one table for Cpf and another for cnpj from the person…
-
0
votes2
answers1756
views -
0
votes1
answer165
viewsQuery with subquery
I need to answer this question: 4) Find the name and address of the customers who rented all the films from the video store. I don’t have a way to test the query, but I will do something like this?…
sqlasked 8 years, 1 month ago Marcos Barbosa 377 -
0
votes2
answers48
viewsInsert error ... Values using oracle error 00936
I’m trying to make an Insert on a table and it’s always giving me error 00936 that says Missing Expression when you arrive at the command line cmd.executenonquery. Can anyone help me? Code I have:…
-
0
votes0
answers100
viewsError connecting to Sqlserver using JAVA JDBC
I’m using the sqlserver lib and my connection class is down here: public class conexao{ //sqlsever private static final String USUARIO2 = "usuario"; private static final String SENHA2 = "senha";…
-
0
votes1
answer937
viewsRunning SQL Server External HD Database
I am starting the construction of a web application using SQL Server and talked to my client to provide the backup of the database avoiding access to its production base, because it has no…
-
0
votes2
answers60
viewsHow to search the bank with three types of user?
Hello I’m doing a college project, it’s an internship site project, it has to be developed in Java WEB with database. It has three types of user, the student, the company and the administrator. I…
-
0
votes2
answers2379
viewsMerge 2 selects into one, showing fields
The 1st select shows the following fields: CONCAT - FILIAL - COD. PRODUTO - DESCRICAO - QNTD. VENDAS PUB. 11 - 1 - 1 - PRODUTO 1 - 10 12 - 1 - 2 - PRODUTO 2 - 20 13 - 1 - 3 - PRODUTO 3 - 30 2nd…
-
0
votes1
answer29
viewsSend AJAX to a table
I have in a database data page inserted in a table: <div class="procurar"> <input type="text" id="search" onkeypress="mandar()"><i class="fa fa-search"…
-
0
votes1
answer63
viewsINSTEAD OF (Deleted table)
I’m having trouble creating this Rigger: CREATE TRIGGER TGmonitoraClientes ON TB_CLIENTES INSTEAD OF DELETE AS BEGIN UPDATE TB_CLIENTES SET clienteAtivo = 0 FROM TB_CLIENTES WHERE CODcliente =…
-
0
votes0
answers154
viewsError while doing Insert in database
I am getting error trying to make an insert in the database. Below. <?php define("CMD_CRIAR_POST", 0); define("CMD_BUSCAR_POSTS", 1); define("CMD_EDITAR_POST", 2); define("CMD_EXCLUIR_POST", 3);…
-
0
votes1
answer1239
viewsSelect with Sql and Dynamic Input
I am trying to make you select below, which pulls data from an sql when selected the option, change the value in input side, also coming from sql database. What would be the best option? Follow the…
-
0
votes1
answer528
viewsSelect field from next line
I need to make a query bringing the second value of a field to the first line, that is, I need the value of the first field of the column "Time1" to be filled with the value of the second field of…
-
0
votes1
answer58
viewsSQL Select unique categories sorted by popularity
I am trying to get a list of categories that are in use and then sort them based on the number of records to be able to assemble a list of categories and use in the site filter. So they must follow…
-
0
votes1
answer499
viewsPrint two foreach variables in a table in different columns - codeigniter
I am trying to print a table that accesses the database and inserts the different values of each array in each column. The problem is not printing the values correctly.. Controller: private function…
-
0
votes2
answers204
views -
0
votes1
answer49
viewsQuery returning unwanted result
In my sql statement: SELECT DISTINCT C.TABLE_NAME,C.CONSTRAINT_NAME,C.COLUMN_NAME FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE C INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS T ON T.TABLE_NAME…