You can get the particular data if date exist in a table row, what "IF" it's "NULL"?
Can you get all NULL data of today? Is it possible using mysql query?
Edited:
I have a question, can you retrieve data that are not recorded for a certain date?
For example:
Janice Student 2017-xx-xx
Paul Student 2017-xx-xx
Mika Student ------
You can retrive those records with date, but can you retrive data that have no values? Is it possible using mysql query? or conditional x looping statement using PHP?
To locate information where there is no value stored use IS NULL e.g.
select * from yourtable where column_name IS NULL
If the column is a string of some type then it might be an "empty string", which looks like no value but isn't NULL, so for this use:
select * from yourtable where column_name = ''
or in combination:
select * from yourtable where ( column_name IS NULL OR column_name = '' )
Related
Is there any possible way I can find and set the column name by giving alias
for example
I have a sql queries which contain 4 column name fields. 3 fields are common in all the queries
id, name, field
and there is another field which column name get change every time but the only common thing in that field it has a postfix as __type
so my sql query looks like this
SELECT * from table_name
id, name, field, system_data__value
is there any possible way I can add alias to the name where I found __type as type
so if I run my queries then it look like this
SELECT * from table_name
id, name, field, type
You may use UNION ALL for to set the aliases to the columns posessionally.
You must know some value which cannot present in some column (id = -1 in shown code) for fake row removing.
SELECT *
FROM (
SELECT -1 id, NULL name, NULL field, NULL alias_for_column_4
UNION ALL
SELECT * from table_name -- returns id, name, field, system_data__value
) subquery
WHERE id > 0 -- removes fake row
It is possible that the values in fake subquery needs in explicit CAST() calls for correct datatype of the output columns setting.
I was hoping to call a dynamic query in mysql-nodejs
the query is something like this
select a
from table
where startdate = ?
and prjId in (?)
and loc in (?)
there will be 3 parameters
`startdate` string
`prjId` array
`loc` array
my question is if the array prjId is null it should get all project id
same in the case of loc also
both are null
one is not null
both arrays are not null
Simply put
select * from table where name in (?)
can it return all rows if nothing is given, which I checked (wont work)
But does there exist something like that
thanks
I keep searching but I can only find answers on the existence in a table but that is not what I am looking for.
I want to know how I would check the existence of a specific keyword inside the entire database.
I tried selecting from every table but got an error:
SELECT * FROM dvd_drives, compatible WHERE mpn = "700577-1C6"
#1052 - Column 'mpn' in where clause is ambiguous
I can use search inside phpmyadmin but how can I use this in a query?
SELECT EXISTS ( SELECT NULL
FROM table1_name
WHERE column_name = 'value'
UNION ALL
SELECT NULL
FROM table2_name
WHERE column_name = 'value'
UNION ALL
... ) AS check_result;
SELECT EXISTS ( SELECT NULL
FROM table1_name
WHERE column_name = 'value' )
*
EXISTS ( SELECT NULL
FROM table2_name
WHERE column_name = 'value' )
*
... ) AS check_result;
The queries checks the existence only (as required in the question), rows with specified value are not returned.
1st query check does the value is present in at least one of the tables, 2nd checks that it is present in each table at least once.
PS. NULL may be replaced freely with any literal value - zero, one, some string literal, etc...
I have created date and resolved date in Table1. Both fields are included in one record.
ID created_date resolved_at
'1xxxx' '18-04-2018' '20-04-2018'
Is it possible that i may use custom SQL function to separate them into 2 records.
I want somehow output like this.
ID date Operation
1xxx. 18-04-2018. Created
1xxx. 20-04-2018. Resolved
SELECT ID,created_date DATE,CASE WHEN CREATED_DATE IS NOT NULL THEN 'Created' end OPERATION FROM TABLE1
UNION
SELECT ID,resolved_at DATE,CASE WHEN resolved_at IS NOT NULL THEN 'Resolved' end OPERATION FROM TABLE1
You simply need to use CASE WHEN and according to which ever column is not null we will make that name as OPERATION.
You can check SQL fiddle here
Try above query.
It will help you.
The simpler solution is:
select id, created_date, 'created' as operation from t
union all
select id, resolved_at, 'resolved' as operation from t;
I need to return the table name and schema name in my query and was unsure of how to do that without using information_schema or if I needed to join on information_schema for desired results. I'm using a mysql database and would like the table and schema within the results of the query below.
SELECT
transfer_ID
, name
, mapping
, records
, email_address
, locked
, active
, NOW() tNow
FROM data_transfer.Transfers DT
I would like to return the table name and schema name within the query above similar to this example.
SELECT table_name,
FROM information_schema.tables
WHERE table_schema = 'db5'
Is this possible without having to specify table_schema?
Desired results would be:
name
mapping
record1
test#email
N
Y
timestamp
data_transfer
Transfers
Just add new columns with the values since you know them at the time the query is run.. It's not like this is Dynamic SQL and the schema and table names change at run time is it?
SELECT
transfer_ID
, name
, mapping
, records
, email_address
, locked
, active
, NOW() tNow
, 'data_transfer' as schemaName
, 'Transfers' as tableName
FROM data_transfer.Transfers DT