Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have two tables like below:
cat
+-------------------------------+
| id | 1 | 2 | 3 | 4 | 5 |
+-------------------------------+
| name | Hi | Ho | Hu | Ha | He |
+-------------------------------+
selected cat
+----------------+
| id | 2 | 5 |
+----------------+
| name | Ho | He |
+----------------+
Expected Output:
1 - > No
2 - > Yes
3 - > No
4 - > No
5 - > Yes
select id,
case when id in (select distinct id from selected_cat) then 'Yes'
else 'No' end
as somecol
from cat;
You can use a case statement to check for the existence of id in the other table.
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 2 years ago.
Improve this question
I have 2 table with diferent data
Finance Orderan
+-----------------+ +---------------+
| id | no_order | | id| no_order |
+-----------------+ +---------------+
| 1 | 1234567890 | | 1 | 1234567890|
| 2 | 0987654321 | | 2 | 0987654321| |
| 3 | 1122334455 | | 3 | 1122334455|
| 4 | 1212121212 | | 4 | 2222222222|
+-----------------+ +---------------+
I want to return diferent data like this:
+-------------------------+
| no_order | no_order |
+-------------------------+
| 1212121212 | 2222222222 |
+-------------------------+
Maybe you need in simple
SELECT t1.no_order, t2.no_order
FROM Finance t1
JOIN Orderan t2 ON t1.id = t2.id
WHERE t1.no_order != t2.no_order
?
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 3 years ago.
Improve this question
Student_ID | First_Name | Last_Name | Examination_date | Exam_grade
| | | |
12345 | John | Doe | 12/01/2019 | 5
67890 | Johny | Bravo | 12/02/2019 | 7
09876 | Johnny | Boy | 12/02/2019 | 3
Hello Good day, I just want to show only the students who passed the exam, that has a minimum grade of 5 above. Thank you so much
here's my query
$conn->query("SELECT * FROM tbl_admission where exam_grade > 5");
use this condition - where exam_grade >= 5
SELECT * FROM tbl_admission where exam_grade >= 5
For having grade 5 or above you should use >= in your query .
SELECT * FROM tbl_admission where exam_grade >= 5
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
My table structure as fallows
+----+------+---------+---------+
| id | name | heading | catid |
+----+------+---------+---------+
| 1 | ajay | xyz | 1:25:22 |
| 2 |sanjay| abc |15:25:45 |
+----+------+---------+---------+
If i get condition catid=22 then get result
+---+-----+----+---------+
| 1 | ajay| xyz| 1:25:22 |
+---+-----+----+---------+
If i get condition catid=15 then get result
+---+-----+----+----------+
| 2 | sanjay| abc|15:25:45|
+---+-----+----+----------+
If i get condition catid=25 then get result
+---+-----+----+----------+
| 1 | ajay| xyz| 1:25:22 |
+---+-----+----+----------+
| 2 | sanjay| abc|15:25:45|
+---+-----+----+----------+
You could use FIND_IN_SET, after replacing the colons in catid with commas:
SELECT *
FROM yourTable
WHERE FIND_IN_SET('25', REPLACE(catid, ':', ',')) > 0;
But a good long term investment would be to normalize the catid data and get those IDs in separate records.
There is also a way to do this using the LIKE operator, but it is ugly:
SELECT *
FROM yourTable
WHERE CONCAT(':', catid, ':') LIKE '%:25:%';
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
i have a task to complete. there is a many to many relationship. the bridge table has been made which looks like
left id right id
+----------+---------+
| 1 | 1 |
| 1 | 2 |
| 2 | 1 |
| 2 | 2 |
| 2 | 8 |
| 3 | 1 |
| 3 | 2 |
| 3 | 4 |
| 4 | 1 |
| 4 | 2 |
| 4 | 3 |
| 4 | 5 |
| 5 | 1 |
| 5 | 2 |
| 5 | 4 |
| 5 | 6 |
| 5 | 7 |
+----------+---------+
i have to display the left id = right id in one row
for example
for left id 1
left1 | right1 righ 2
for left id 3
left3 | right1 right2 right 4
how do i do this ? i have tried joining table , doesn't work
I think you can use a simple query to acheive this using GROUP BY and GROUP_CONCAT()
SELECT left_id, GROUP_CONCAT(right_id SEPARATOR ' ') as rigth_id
FROM left-right
GROUP BY left_id;
This is a reasonably straightforward application of GROUP_CONCAT() and GROUP BY. (http://sqlfiddle.com/#!9/ed7e1/2/0)
SELECT leftId,
GROUP_CONCAT(rightId ORDER BY rightId) rightIds
FROM bridge
GROUP BY leftId
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
field_data_body
+----------+---------------------+
| entry_id | body_value |
+----------+---------------------+
| 1009 | content |
+----------+---------------------+
| 1020 | |
+----------+---------------------+
| 1025 | more content |
+----------+---------------------+
i_posts
+------+---------------+
| id | html |
+------+---------------+
| 1009 | |
+------+---------------+
| 1020 | |
+------+---------------+
| 1025 | |
+------+---------------+
i_posts
+----------+---------------------+
| id | html |
+----------+---------------------+
| 1009 | content |
+----------+---------------------+
| 1020 | |
+----------+---------------------+
| 1025 | more content |
+----------+---------------------+
Hi, I'm trying to transfer the body_value column into the html column and am not sure how to execute this. I have a table called i_posts and I have all the id's of my posts that i'm trying to transfer. However in the field_data_body table it doesn't have content for every single entry_id. Is there a way to move the body_value into the html column while keeping the correct id? Thanks for any help in advanced!!
- Blake
Edit:
This is what you need.
UPDATE i_posts AS i, field_data_body AS f SET i.html = f.body_value WHERE i.id =f.entry_id
I did a small post about it.