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
answer27
viewsTotal digit check in Mysql
Well, I need to select values formed by a total of 5 digits that start with "1" and end with "0". In the table, this attribute is of the decimal type. How can I perform this SELECT?
-
0
votes0
answers44
viewsSelect data from 2 PHP tables
Good people, I have here two tables with the following structure: 1 - Orders, 2 - Order_items. I need to select the data of each and display the purchase details, example: Order #1 (table 1) Client:…
-
0
votes1
answer171
viewsDoubt in HQL when doing Sum function
I have a doubt in hql. My system has 3 tables Tabela1 and table 2 and table 3 table 3 stores the primary key records of Table 1 and table2 for making relationships. Table 1 can contain N…
-
0
votes2
answers49
viewsHow do I count the amount of items in a repeated field?
I have a table with the Ctrlcarganum field that has a record of the cargo number of a truck. I need to make a consultation that brings the total of this field. Until I could make the consultation…
-
0
votes3
answers1155
viewsBring more than one line into a Subquery Sql Server
I am working with 2 consultations and would like a way to unite the 2 in one, however I am having difficulties. I have the following example: Table T1: CD PF Data Total 1 JSL001 15/03/2018 100 Table…
-
0
votes0
answers70
viewsError 1215 Mysql
First of all, I would like to say that I have checked several questions about this here and no solution has worked. I am giving alter table in the working table to add two Foreign Keys...one of them…
-
0
votes1
answer51
viewsSQL Select max is not working well
I have this code but it’s not working well I don’t know why: SELECT email, MAX(a4cor) as a4c, MAX(a4preto) as a4p, MAX(a3cor) as a3c, MAX(a3preto) as a3p, MAX(totalcopias) as total FROM dados GROUP…
-
0
votes2
answers52
viewsDoes SQL Educational SERVER have fewer resources?
Good afternoon, you guys, Today I came across a company that uses in production SQL SERVER Educational, I know that this is not correct because this tool is only for non-profit study. But even so, I…
-
0
votes1
answer453
viewsAdd two created columns
I need to add two columns created according to a date and grouping by another column. I need to create a new column called previous balance that disappears ( VALORDEBITO + VALORCREDITO) and group by…
sqlasked 6 years, 8 months ago Julio Cezar Lidani 1 -
0
votes2
answers4216
viewsFunction MAX only 1 (one) record on Oracle
Could someone give me a hand in using Oracle’s Function MAX()??? I need to do a query that returns only the last record of a history table, but I need to return 3 (three) columns of this record…
-
0
votes2
answers80
viewsDate sorting problem with DATATABLE plugin
Friends, I am having trouble sorting a table with Datatable plugin and I do an SQL query already ordered by a field and when it presents the table with the plugin it reorders otherwise and I have…
-
0
votes0
answers39
viewsMysql - What would be the pure sql query that would be equivalent to Laravel Sync in a pivot table?
When I work with Laravel in a pivot table where we have only the fields user_id and post_id we use something similar to $user->posts()->sync([3,4]) and the pivot table will be updated with…
-
0
votes2
answers970
viewsSQL SERVER - Substring
Good morning Sirs I would like to know how to select a value within a table where it starts with a certain value For example : Campoemail [email protected] [email protected]…
-
0
votes1
answer40
viewsUse LEAD to catch the next date
I am trying to set up a query that will answer the following question: Number of customers (registration in the case) that has a reading date of 26 days, number of customers that has reading of 27…
-
0
votes1
answer51
viewsSQL CASE command
I’m trying to select only 5 characters from the field description, tried several ways and it doesn’t work, the eating I’m giving is this: SELECT description = CASE WHEN LEN(description) > 5 THEN…
-
0
votes0
answers104
viewsHow should I name variables in the SQL language?
Is there any pattern of naming variables in SQL? I want to define the most standardized possible,for the following cases: Appointment of the database Table nomination Naming of columns Appointment…
-
0
votes1
answer69
viewsLock in SQL Server and Oracle
Hi, I’ve been running some lock tests on SQL Server and noticed a difference from Oracle. In oracle I did an update on a line without effecting commit or rollback and in another session I was able…
-
0
votes0
answers57
viewsHow to return the value of a sql database combobox in a Jtextfield?
In my program I have a register of customers in which contain two combobox. One is districts and the other is counties. As I show in the next photo in the comboDistricts has several districts of…
-
0
votes1
answer41
viewsDoubt about Mysql Query
What code is required to display all a user’s posts? I did something like this in PHP: "SELECT * FROM postagens WHERE id='$p_id' AND u_id='$u_id';"; But always returns 0 lines :( CREATE DATABASE IF…
-
0
votes0
answers96
viewsUsing wpdb->Insert correctly in the function
I am trying to enter the form data created by the plug Contact Form 7 for my table 'wp_wpdatatable_2', I created a hook using add_action and all right, but it does not send to the bank and I do not…
-
0
votes1
answer197
viewsSort by year SQL data
I have a table with 2 columns (one with date (YYYY,MM,DD) and another with a numeric value). I want the table to be ordered only per year and in case of entries with the same year the "tie-breaker"…
-
0
votes3
answers172
viewsHide duplicate SQL values
Well, I’m doing a little approval process project. I need to consult two tables with data that may be the same, but I need this same data don’t show up, in case they get hidden. Example: TABELA1…
-
0
votes0
answers32
viewsField of research and pagination
I have as objective the realization of a field of research, as also the pagination, both worked until I realized a popup that was intended to present the data of each client that were inserted in…
-
0
votes0
answers49
viewsCompare 2 banks
Good morning, I have two Access banks, one is copy of the other, but one of them has a record that was added, I do not know in which table or field, I would like to compare them and find which…
-
0
votes0
answers42
viewsList phones on the same line
i have a database that has the following tables: contact, phone and contact table_phone since the cardinality in my application has to be N:N. When I make a Join Inner, the return brings me, for…
-
0
votes4
answers487
viewsFill a datatable from a txt
I have a datareader writing directly into the text file, int count = dataReader.FieldCount; while (dataReader.Read()) { for (int i = 0; i < count; i++) { file.WriteLine(dataReader.GetValue(i)); }…
-
0
votes1
answer88
viewsDate range query in a given time
I have a query that takes all the data between days. However, I would like him to take this data only in an interval of hours (from 08:00 to 17 for example). My query currently looks like this:…
-
0
votes0
answers106
viewsCreate a Boolean column in Oracle Database
In an oracle bank I have to create a column with the Boolean type ALTER TABLE dbamv.prepad ADD editable BOOLEAN default FALSE; But the database displayed an error message: ORA-00902: invalid data…
-
0
votes1
answer34
viewsHow to get the most distant date in Mysql?
I have the following tables boi ------------------------------- id | peso | data_pesagem | ------------------------------- 1 | 175 | 2019-01-02 | 2 | 200 | 2019-01-03 |…
-
0
votes3
answers53
viewsFor each value of a table show the corresponding if no zero is shown
What I want to do is this: Show for each row of the seller table the number of passes sold, but if you have not sold any pass show 0. There is a previous query in the system that makes similar, but…
-
0
votes0
answers241
viewsUncaught Pdoexception error: could not find driver
I’m trying to connect the sql server with php7, insert the database data into the php class, insert the extensions into the php folder in xamp, and in php.ini, but this error appears when I run the…
-
0
votes1
answer225
viewsHow to validate higher value received in mysql?
I have a query that returns the last accesses of the users in the system. I would like to know how I could treat to return only those dates that are longer than 15 days. This is the consultation:…
-
0
votes2
answers218
viewsInner Join with subselect codeigniter
How to create a function that brings the same query result below using codeigniter? SELECT AC.cod_setor,AC.cod_coletor ,SUM(ac.quantidade) AS quantidade FROM item_inventarios AC INNER JOIN ( SELECT…
-
0
votes0
answers60
viewsHow to calculate the next available house?
I’m doing a project right now and I’m having a problem with an algorithm. Taking into account the 4 directions ( North,East,South,West), if the user chooses one of the 4, should be allocated the…
-
0
votes1
answer105
viewsDatabase based query listing
First of all, I apologise if the question is vague, as it is a very broad subject. Today I have a student registration and consultation system, where the query is made exclusively by CPF, since it…
-
0
votes1
answer36
viewsJoin SQL Tables
I have two tables: curso curso_configurar With the following structure: My question is: I need to include within the curso_configurar, the courses that will be configured, until there is OK.…
sqlasked 6 years, 8 months ago Sr. André Baill 6,946 -
0
votes2
answers56
viewsSQL sub-consultations with counter
I have a table like this: ++++++++++++++++++++++++++++++++++++++++ + Nome | Cargo | Estado + + ++++++++++++++++++++++++++++++++++++++ + Joao | Estagiário | RJ + + Maria | Analista | RJ + + Thiago|…
-
0
votes0
answers75
viewsDoes not update value
Calculus and values return me all right, but when overriding the previous value and add the new one it does not change, keep the old one. Compra Controller: public ActionResult Update(CompraModel…
-
0
votes3
answers261
viewsCRUD Object Oriented Programming
I’m a little confused about how we persist in an object-oriented programming structure, I’m not sure how to explain it, let’s imagine the object Person and for example through Heritage create the…
-
0
votes1
answer31
viewsQuery SQL Help
select T.n_acid,T.marca from (select n_acid, veic_seguro, marca from marca_acid as ma, veiculo as v where ma.veic_seguro = v.n_veic) as T group by T.n_acid, T.marca; This query returns the table…
-
0
votes1
answer79
viewsDate problem in PHP (SELECT)
Good afternoon! I have a PHP question! I have a code to show all the fields of a table where the date is 2018. $sql_manutencao = 'SELECT * FROM manutencao WHERE data_trabalho LIKE "2018%" AND…
sqlasked 5 years, 6 months ago João Simões 98 -
0
votes0
answers223
viewsjava.lang.Illegalargumentexception: org.hibernate.hql.internal.Ast.Querysyntaxexception: Unexpected AST Node: query
I’m having to make a SELECT in JPA that contains an ORDER BY by selecting from another table. Small representation of tables: When I did by SQL it was normal, but when turning into JPA, it did not…
-
0
votes1
answer95
viewsReturn data from 01 column in 03
I am working with some data in a table, in which I made a SELECT that one of the columns returns the status of the processes that are in progress in our queue. The data in this column are for…
-
0
votes1
answer764
viewsHow to Select Tables in Different SQL SERVER 2008 and 2012 Databases
Currently I have 1 database in SQL SERVER 2008R2 and another SQL SERVER 2012. I HAVE AN APPLICATION THAT USES THE BASIS IN 2008R2 AND I NEED TO CONSULT DATA THAT IS IN 2012. WHICH IS THE BEST WAY?…
-
0
votes1
answer169
viewsCrop a sql server string
How can I cut part of a string, for example : "2017/12/teste.jpg", I only need to pick up "test.jpg".
sqlasked 5 years, 6 months ago Victor Henrique 53 -
0
votes1
answer472
viewsSELECT TOP that brings all the results, something like TOP all, exists in SQL Server?
During my studies, I tried to sort the records and put those that are NULL in the end, I did it this way: SELECT tbl1.firstname, tbl1.mgrid FROM ( SELECT TOP 100 firstname, mgrid FROM HR.Employees…
-
0
votes1
answer225
viewsOracle - Cursor
I’m studying PL/SQL and testing the use of CURSOR, but I’m not able to test an example: SET SERVEROUTPUT ON DECLARE V_NAME VARCHAR2(50); CURSOR CUR_CURSOR IS SELECT FIRST_NAME FROM EMPLOYEES; TEMP…
-
0
votes2
answers143
viewsDouble query in 1 query
I have 2 tables one of users and another of subscribers, I have an Internet that sends to the table of subscribers the email of the user who registered and the name of the channel 1st users id |…
-
0
votes1
answer62
viewsConsult in 2 table
I do not know how to consult in two tables of the same bank. tb_chamados id = 1 | 2 fkidempresa = 47 | 33 resumo = descrição do chamado | descrição do chamado tb_empresas id = 47 | 33 nome = Nome da…
-
0
votes0
answers22
viewsHelp on this select I need a clause to delete records
Good evening, I need to solve a problem in this consultation SELECT * FROM campanha WHERE limite > '0' AND tipo = '1' ORDER BY rand() LIMIT 1 I need to do the same query plus deleting all…