Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
How to get the data with different field names in MYSQL?
I have a order table and columns as follows:
order_id, order_name
in results I want the field names as id and name like below:
{id: 1, name: "swamy"}
what's the best way to do this?
Use SQL aliases like below
select order_id AS id, order_name AS name from table_name;
For more ref: SQL Aliases
Simply use mysql alias for the same.
SELECT
order_id AS id
order_name AS name
FROM order;
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
here is my query
SELECT distinct(DESIG_NAME)
FROM employees
WHERE GRADE like ("L0007", "L0008", "L0009");
I want to find grade of employee in one single statement
grade are level e.g., level7, level8, etc something like this
DISTINCT is not a function, and also you want WHERE IN (...):
SELECT DISTINCT DESIG_NAME
FROM employees
WHERE GRADE IN ('L0007', 'L0008', 'L0009');
SELECT distinct(DESIG_NAME) FROM employees where GRADE like 'L0007' or like 'L0008' or like 'L0009'
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Here is the MySQL code
select id, name, code, batch_id from subjects where batch_id=18;
In this query i want name to be subject name during the execution. So this is the whole problem.
Do you want a column alias in the resultset?
select id, name as subject_name, code, batch_id
from subjects
where batch_id = 18
This changes the name of column name to subject_name in the result of the query.
I don't see what your question has to do with the where clause.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a column media_type with sample following values
*media_type*
-------------------
socialmedia, paper
tv
paper, tv
pamplet,board
tv,board,pamplet
I would want to filter my promotions which are being advertised through only one media.
You can use locate():
select *
from mytable
where not locate(',', media_type)
This phrases as: get all rows whose media_type is not null and does not contain a comma.
A more portable approach uses like:
select *
from mytable
where media_type not like '%,%'
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
i have a problem with MySQL. My table has a ID, but when i select the data and order by ID ASC, the id is out of order.
As you can see, after WI10 the ID is WI100, the ID should be WI11. Any solutions? Sorry for my bad eng, thank you!
The column cid is sorted alphabetically because it is not a number.
If its pattern is always like WIXXX you can sort the table like:
order by substr(cid, 3) + 0
This extracts the numeric part after the first 2 chars and implicitly converts it to a number.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
There is a table called member_info and this table have 2 rows (member_id and sponsor_id)
table looks like :
member_id (1,2,3,4,5,6,7,8);
sponsor_id (,1,1,1,2,5,5,5);
Now i need to pick those member_id's who are not in sponsor_id like
member_id(3,4,6,7,8);
Any help Appreciated.
You can use the NOT IN function with a sub-query:
SELECT `member_id`
FROM `member_info`
WHERE `member_id` NOT IN (
SELECT DISTINCT(`member_id`) FROM `sponsor_info`
)
Subqueries introduced with the keyword NOT IN also return a list of zero or more values.
SELECT member_id
FROM member_inf
WHERE member_id NOT IN (
SELECT DISTINCT(member_id) FROM sponsor_info
)