How to retrieve unique data from Mysql database table - mysql

I have a table with four columns namely core,domain, Prog_StdName, LP_Prj_Desc.
I want to retrieve unique the data, where LP_Prj_Desc column is dependent on Prog_StdName and Prog_StdName is dependent on domain, and domain, is dependent on `core.
Below image which Ihave tried using the select statement.
SELECT `core`,`domain`,`Prog_StdName`,`LP_Prj_Desc`
FROM `cf_ls`
WHERE `core` <> 'PS'
this show the duplicate rows enter image description here
Actually I need to retrieve the data like below imageenter image description here

SELECT distinct `core`,`domain`,`Prog_StdName`,`LP_Prj_Desc`
FROM `cf_ls`
WHERE `core` <> 'PS' ;
Try this one

Related

What is the new table name after joining two tables in sql?

I read the previous posts but I couldn't find one that answered my question.
What would be the name of the table that is made by joining two tables? The reason why I need the name is because I would like to change the column name of the new table using the ALTER TABLE (Table name) RENAME COLUMN (A) to (B). If there is no specified name, how can I name the new table?
ex
SELECT
client_id
,last_name
FROM INDIVIDUAL_CLIENT
UNION ALL
SELECT
client_id
,bus_name
FROM BUSINESS_CLIENT;
I would like to rename the column to last_name/bus_name instead of last_name
In the case of a query what temporal table a query might create internally is not relevant, because you a making a query and getting data back, it doesn't stay in the database as a table, there is no such table. Unless we make it.
if You want TSQL to change a column name it would affect your union query and I base my answer on Your
'I would like to rename the column to last_name/bus_name instead of last_name'
And think this is what you're looking for. Please correct me if it isn't.
In generic SQL what we're doing is putting a label on both projections that are to be displayed in the same column
SELECT
client_id
,last_name [last_name/ bus_name]
FROM INDIVIDUAL_CLIENT
UNION ALL
SELECT
client_id
,bus_name [last_name/ bus_name]
FROM BUSINESS_CLIENT;
update, in MySQL notation uses AS and quotes instead of angle brackets
SELECT
client_id
,last_name as "last_name/ bus_name"
FROM INDIVIDUAL_CLIENT
UNION ALL
SELECT
client_id
,bus_name as "last_name/ bus_name"
FROM BUSINESS_CLIENT;

combobox with data from several fields in access

I have created a table with several columns and a related form. In that form, I have created a combobox to show the columns of the table in differents rows in combobox.
I have 3 fields in my table: product1, product2 and product3 for a same order I have named with a number. When I create the combobox, values show in 3 differents columns in the same row so I can just select the data from the first row and column. But what I need is the field's data displayed in different rows instead showing data in different columns.
I researched in forums, and I read It can be solved with a join query and selecting that in row source in combobox menu, but I have tried it and I got the same result. I don´t know what am I doing wrong. I'd appreciate your help.
Thanks in advance.
You have to pivot the results
this is an example of how to restructure using sub queries bad data designs
SELECT *
FROM
(
SELECT QualifierID -- <--- this is a unique identifier
,
(
SELECT QualifierText
FROM [QDB].[dbo].[Qualifier] x
-- this is how you tie the unique identifier and grab a specific element by itself
-- also pay attention to how we're making it equal to q.QualifierID,
-- which is the alias to the table below
WHERE QualifierID=q.QualifierID
) AS QualifierText
,
(
SELECT [ExampleText]
FROM [QDB].[dbo].[Qualifier] x
-- this is how you tie the unique identifier and grab a specific element by itself
-- also pay attention to how we're making it equal to q.QualifierID,
-- which is the alias to the table below
WHERE QualifierID=q.QualifierID
) AS ExampleText
,
(
SELECT [WhenModified]
FROM [QDB].[dbo].[Qualifier] x
-- this is how you tie the unique identifier and grab a specific element by itself
-- also pay attention to how we're making it equal to q.QualifierID,
-- which is the alias to the table below
WHERE QualifierID=q.QualifierID
) AS WhenModified
FROM [QDB].[dbo].[Qualifier] q -- this is a table alias
) z -- this is the alias fo the subquery combining everything together.

MySQL - Select rows from multiple tables based on the tables' names

I'm currently trying to set up a simple database via MySQL.
To sum up, I have a first Table 'A' containing a column 'name' and a column 'value'. Next I have a bunch of other tables 'name1', 'name2'... 'nameN' whose name actually correspond to one of the name stored in A.name.
Now I would want to select stuff from those tables based on a desired value for A.value. Something like that :
SELECT * FROM ( SELECT name from A WHERE A.value = desired_value );
Thanks a lot for your help !

Is there way to add multiple values to 1 ID in access

I have a table that has Act ID, and another table that has Act ID, percentage complete. This can have multiple entries for different days. I need the sum of the percentage added for the Act ID on the first tableZA.108381.080
First table
Act ID Percent Date
ZA.108381.110 Total from 2 table
ZA.108381.120
ZA.108476.020
ZA.108381.110 25% 5/25/19
ZA.108381.110 75 6/1/19
ZA.108381.120
ZA.108476.020
This would be generally considering not good practice. Your primary key should be uniquely identifiable for that specific table, and any other data related to that key should be stored in separate columns.
However since an answer is not a place for a lecture, if you want to store multiple values in you Act ID column, I would suggest changing your primary key to something more generic "RowID". Then using vba to insert multiple values into this field.
However changing the primary key late in a databases life may cause alot of issues or be difficult. So good luck
Storing calculated values in a table has the disadvantage that these entries may become outdated as the other table is updated. It is preferable to query the tables on the fly to always get uptodate results
SELECT A.ActID, SUM(B.Percentage) AS SumPercent
FROM
table1 A
LEFT JOIN table2 B
ON A.ActID = B.ActID
GROUP BY A.ActID
ORDER BY A.ActID
This query allows you to add additional columns from the first table. If you only need the ActID from table 1, then you can simplify the query, and instead take it from table 2:
SELECT ActID, SUM(Percentage) AS SumPercent
FROM table2
GROUP BY ActID
ORDER BY ActID
If you have spaces other other special characters in a column or table name, you must escape it with []. E.g. [Act ID].
Do not change the IDs in the table. If you want to have the result displayed as the ID merged with the sum, change the query to
SELECT A.ActID & "." & Format(SUM(B.Percentage), "0.000") AS Result
FROM ...
See also: SQL GROUP BY Statement (w3schools)

Subquery results more than one values

I have two tables:
table_people
col_name
col_sex
table_gender
col_male
col_female
Suppose the table_people consist three rows, (a,'M'),(b,'M'),(c,'F').
Now I need a query(subquery) to insert this first table value in second table as:
(a,c),(b,'').
If it is possible in mysql?
You table structure is bad.
My suggestion is to drop table_gender because it doesn't make sense at all. You already have a list of person with gender on table table_people.
You can generate a VIEW, if you want to list the gender separately.
CREATE VIEW MaleList
AS
SELECT col_name
FROM table_people
WHERE col_sex = 'M'
and another view for list of females only.
CREATE VIEW FemaleList
AS
SELECT col_name
FROM   table_people
WHERE  col_sex = 'F'
First of all the table structure is bad. I dont see a point of saving M or F in another table when you col_sex in your table_people. Still if you want to do it, first you have to specify a foreign key connecting the two tables.