Most voted "select" questions
USE THIS TAG ONLY WHEN REFERRING TO DATABASE. SELECT is an SQL statement that returns zero or more rows, from one or more base tables, temporary tables, or views in a database. DO NOT USE to refer to the HTML "select" element, in which case use [html-select].
Learn more…807 questions
Sort by count of
-
17
votes3
answers1699
viewsWhy doesn’t "= NULL" work?
In the SQL Server, by fetching all records with a given field with value NULL, if I do so no record is returned: SELECT * FROM clientes cli WHERE cli.cpf = NULL But if you use the following syntax:…
-
12
votes4
answers3355
viewsPHP login with permission levels
I have a problem with my code to separate logins. I want when a login with Rank = 1 it redirects to a page, and when the Rank is = 0 go to another. I tried to do it but I didn’t get it because he…
-
12
votes5
answers35616
viewsSELECT condition WHERE with multiple values in the same column
I have two tables in my bank and perform JOIN with them. A table is a list of people and the other characteristic list of that person. By logic there is only one person and each person can have…
-
11
votes1
answer8640
viewsLimit and Offset for Web Paging in SQL Server
I am working with PHP and have about 8000 records currently on DB. As it is for a web page, I need to make a pagination to be able to read the data. From what I understand, I have to do something…
-
10
votes5
answers26385
viewsWhat is the best practice to know if an Row exists in a SELECT in Mysql?
For example, when we check if a user is already registered in the table, we do not need any data return by query, just check if the number of Rows is greater than 0 (num_rows > 0). Us scripts and…
-
10
votes2
answers108
viewsHow to order a select 1 to 255?
Personal I have a query of a table with Ips numbers from 1 to 255 of various ranges. When I do SELECT IPS FROM ipvalidos WHERE REDE ='{$rede}' ORDER BY IPS It selects from 10.0.0.100 before…
-
9
votes1
answer58526
viewsHow do I make a SELECT in 2 or more Tables with 2 or more conditions?
I have a problem making a select with the following conditions: I want to show the data either with condition1 or with condition2 Select * tabela inner join tabela2 WHERE campo = 0 and campo2 = ''…
-
9
votes1
answer7577
viewsHow to customize the arrow of a select
I have a price list, it has a select for the person to choose the payment cycle as shown in the image: which I did with CSS: -webkit-appearance:none; background:#E9E9E9…
-
9
votes2
answers18476
viewsoptimized way to recover last mysql ID
Which is the most optimized way to recover the last table id? I tested these two methods and the orde by took a long time. There is some beyond these? Note: nãp will be a query after Insert. It will…
-
9
votes1
answer677
viewsPHP works with cache?
I am noticing that my application is occurring some error, or else my browser is always storing cache, even if I perform the cleaning. I have a file .php and in it contain the function loadEvent,…
-
9
votes1
answer877
views -
8
votes1
answer3372
viewsSql - Select first and last record
I have the following tables: CREATE TABLE tb_lote ( id_lote integer NOT NULL DEFAULT nextval('tb_lote_seq'::regclass), ds_lote character varying(255), CONSTRAINT pktb_lote PRIMARY KEY (id_lote) );…
-
7
votes1
answer489
viewsCompare COUNT from two tables
I have two tables and I must return the total of the table with more data, I am doing so: SELECT CASE WHEN ((select count(*) as `familiar` from tb.familiar)) > ((select count(*) as `personal`…
-
6
votes3
answers25254
viewsSubtract date and display in YEARS, MONTHS and DAYS
SGBD: Mysql Problem: How to replace the current date with a specific date and return the value in YEARS, MONTHS and DAYS in a query? Example: DADOS DataAdmissao dataAtual 2010-04-07 2014-06-27 (este…
-
6
votes1
answer616
viewsQuery to join one column from another
I have tried unsuccessfully to get a result. I have the table with the following login and logout information: |Group |User |EventDate |Event |Camp ------------------------ |Evolution |1012…
-
6
votes2
answers1238
viewsWhat is a "0" field in the SQL SELECT?
I didn’t understand the use of 0 in this code: SELECT substring ... 0 AS PARCELADO, ... FROM ... What does he do?
-
6
votes1
answer2147
viewsPass variable value inside nested SELECT
Assuming the following query where we are selecting values, grouping them and then re-grouping the result: SELECT CONCAT (b.label, '|', b.slug) FROM ( SELECT group_concat(name SEPARATOR '$') AS…
-
6
votes3
answers280
viewsHow to mount SELECT?
I have a Products table with: ProCodigo - Primary Key de Produto ProNome And another Price History table with: HisCodigo - Primary Key de Histórico HisData HisPreco ProCodigo - Foreign Key de…
-
6
votes3
answers475
views -
5
votes3
answers51716
viewsSQL Server - Check duplicate data in two simultaneous fields
DBMS: SQL Server 2014; Problem: I need to know which records are duplicated, so that it is checked in two simultaneous fields, that is, if the field "CPF" with the value '83971465842' and the field…
-
5
votes3
answers11223
viewsWhat is the MINUS command for and how it works on oracle
I’ve never seen this command before and I haven’t found it here either, I don’t know if it has another name and from the Oracle documentation I couldn’t understand exactly how it works. I just want…
-
5
votes4
answers3288
viewsSelect with redirection
I can’t program! but I can make small changes. I need to create aselect and when the person chooses the item, it is redirected <select> <option value="Vilhena">Vilhena</option>…
-
5
votes3
answers7043
viewsHow to make a left Join using a Where condition?
I have two tables: category -------- id | nome | imagem user_follow_category -------------------- id | from | to | date Note: the relationship of the two tables is given by category.id and by…
-
5
votes2
answers64
viewsSELECT returning data not seen by a particular user
I’m having a hard time putting together Query I have 2 tables: video_visualizacoes with the fields visualizacao_id, video_id, conta_id (This field refers to the user who viewed the video)". videos…
-
5
votes2
answers658
viewsOrder consultation in the interim
I am trying to list a certain product category. example. $consulta = $pdo->prepare("SELECT * FROM msg where tema = :tema;"); $s = 'mensagens-de-aniversario'; $consulta->bindParam(":tema", $s,…
-
5
votes1
answer95
viewsConcatenate two sql
I have the records: |DT_OBS | DESC_OBS | COD_TURNO | COD_PERIODO| |01.10.16| TESTE 01| 1 | 1 | |01.10.16| TESTE 02| 2 | 1 | |01.10.16| TESTE 03| 1 | 2 | |02.10.16| TESTE 04| 1 | 1 | |02.10.16| TESTE…
-
5
votes2
answers1943
viewsUsing AND inside an INNER JOIN can?
I wonder if it is possible to use AND within a INNER JOIN, example: SELECT * FROM tab1 INNER JOIN tab2 ON tab2.id2 = tab1.id1 AND tab2.camp1 = 'valor' INNER JOIN tab3 ON tab3.id3 = tab2.id2; I gave…
-
5
votes2
answers2991
viewsSQL for last month and last two months
Hi. I’d like a hand here. I need to get the records: Mysql bank 1) last month 2) last quarter 3) Current year SELECT id, data, lote, modelo, qtd FROM controle_diario WHERE modelo like ? The table is…
-
5
votes2
answers10554
viewsSelect with "different" expression with two conditions
I wonder if there’s any way to make a select using a where for a field with the parameter other than < >, where it has two or more items. To facilitate follow example: select * from…
-
5
votes2
answers26234
viewsSELECT INSERT in Oracle using Sesquence nextval and group by
Good morning, you guys! I’m trying to make an Oracle select using a SEQUENCE in id, but is giving error on account of a group by no select. Dry up my SQL: INSERT INTO SUP_T(ID, DESCRICAO) SELECT…
-
5
votes1
answer77
viewsQuery to find if value is between "1|3"
I have a table units that represents the number of dormitories of the buildings: id| dorm 1 | 1|3 In this case above means that id 1 has units with 1 or 3 dormitories. Then I have a search using…
-
5
votes2
answers69
viewsSort a Select by criteria outside the database
I would like to create a SELECT with the personal relationship here of my company. SELECT função, nome FROM responsavel; So far so good. But as ordered by the Manager, passing by the Incumbent,…
-
5
votes1
answer438
viewsHow to join 2 SQL queries into a single one (one is a mean value calculation and another search criteria with BETWEEN
I’m setting up a system that finds providers in a specific region, calculates the average value charged by them and brings this value. But before that he will only pick up the providers that are…
-
5
votes1
answer556
viewsCondition in Select - SQL
I have a table where we store the priorities of output of supplies per customer, for example: cliente | codigosuprimento | prioridade | quantidaestoque 1 | 500 | 1 | 20 1 | 501 | 2 | 10 1 | 502 | 3…
-
5
votes2
answers319
viewsWhat is considered when ordering a varchar field? Being filled in by numbers
I have a table with the birthday of the month, for a reason of use here we should store this as varchar. When using it it is necessary to sort by date from the most recent to the oldest, the same…
-
5
votes2
answers255
viewsReturn the highest value between columns and the row ID of that highest value
Let’s say I have two columns in my table, column A and B. +-----+-----+-----+ | ID | A | B | +-----+-----+-----+ | 1 | 500 | 681 | +-----+-----+-----+ | 2 | 980 | 101 | +-----+-----+-----+ | 3 | 110…
-
5
votes3
answers141
viewsResult range
I have a table where records are saved every 3 seconds 24 hours a day Table: myTable dado1 dado2 dado3 data "135,05" "134,69" "135,10" "2018-11-13 15:38:16" "132,00" "131,91" "132,61" "2018-11-13…
-
4
votes1
answer1007
viewsPass Javascript variable to PHP body
I’ll try to get as much detail as I can about my problem. I have an HTML select that pulls your options directly from the database, as per the code below: $conn = new mysqli('localhost', 'root', '',…
-
4
votes3
answers843
views -
4
votes2
answers1405
viewsHow to send two values per parameter with a single option selected? PHP
I need to send two values per parameter to another page, however value select tag only sends one... How could I send two? Follows the code: <option value="<?php echo $data->format("d/m/Y");…
-
4
votes1
answer1914
viewsProcedure oracle to copy data between tables
I need to make a trial copy of my TAB_FORNECEDOR table, everything you have in it and pass to TAB_FORNECEDOR2 table. I know I need to make a loop cursor, a commit delete before everything, can give…
-
4
votes1
answer4598
viewsHow to list a sample of all tables in a Mysql database?
I need to sample all tables in a Mysql database, for example through a SELECT * ... LIMIT 10. I already have the code that returns all tables of the current database: select table_name from…
-
4
votes1
answer305
viewsCorrect syntax for SELECT and INNER JOIN in Zend
I believe it’s a simple question, but because I don’t know 50% of Zend I’m racking my brain, so here goes: $sql = $db->select() ->distinct() ->from(array('cli' =>…
-
4
votes1
answer493
viewsHow to mount SELECT in lambda C#?
I recently asked for help to assemble a SELECT to bring the price of products How to mount SELECT They gave me this solution that worked perfectly: SELECT P.PROCODIGO, P.PRONOME, H.HISPRECO FROM…
c# sql select entity-framework-6 lambda-expressionsasked 8 years, 9 months ago André Morais Martins 367 -
4
votes1
answer819
viewsHow to customize a Select in columns?
Guys I have a select that shows CODE | TITLE | DESCRIPTION | UF 0001 | TESTE1 | NEW ITEM 1 | SP 0002 | TESTE2 | NEW ITEM ADD 2 | SC See that the column is disfigured, I would like to align this with…
-
4
votes2
answers2248
viewsLatitude and Longitude Calculation - Approximation
You guys, I’m in a bit of a pickle... Currently I have the data Latitude and Longitude of business registers in my database, with this I need to bring data next to me, in case would have latitude…
-
4
votes2
answers1405
viewsSUM in SELECT with LEFT JOIN being multiplied
I have 3 tables in MYSQL. Bill: id nome 1 caio 2 zé 3 marcelo Followers (the account id, that is, the user has 2 followers): idqual 1 1 2 2 2 3 Products (the account id, that is, the user caio has 3…
-
4
votes2
answers40
viewsHow to change the value of fields in a column?
I am with a simple doubt but I could not find a solution. The same way I can when I use select bring an empty column using select a.x,NULL as y,a.z from DADOS a, how can I make a column instead of…
-
4
votes1
answer139
viewsRecover last row inserted in table with non-sequential primary key - Mysql
It is possible to know which was the last row inserted in a Mysql table where the primary key is not sequential? I have a table where the primary key consists of two columns that are FK, so they…
-
4
votes2
answers2957
viewsI need a new Random number for each line in an sql(server) query
I use the sql server. I need to use a Random number in several different columns (the same Random number) but I want a new Random number for each row... for example, let’s assume that TABELAX has…