13

MYSQL SELECT OF TWO TABLES AND CUTTING QUERIES

 3 years ago
source link: https://www.codesd.com/item/mysql-select-of-two-tables-and-cutting-queries.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

MYSQL SELECT OF TWO TABLES AND CUTTING QUERIES

advertisements

I have two tables wp_term_relationships and wp_term_taxonomy

When I do the following SELECT * FROM wp_term_taxonomy WHERE parent = '17' I get the image below

5hhLv.png

Then I do SELECT * FROM wp_term_relationships WHERE term_taxonomy_id = '28'

Which outputs

mxWbx.png

The object_id then gets used SELECT * FROM wp_term_relationships WHERE object_id = '88' and this shows me the terms for this item.

j6VnY.png

What I would then like to do is show next to term_taxonomy_id the taxonomy name from the following table

V5uK4.png

I apologise this is a long winded question but I hope there are people who would be able to help and possibly simplify it so that from my initial query of where the parent=17 I am able to only show DISTINCT taxonomy of where the taxonomy is equal to product_brand


You can replace your last query by:

SELECT wptr.*, wptt.taxonomy
FROM wp_term_relationships wptr
INNER JOIN wp_term_taxonomy wptt ON wptr.term_taxonomy_id = wptt.term_taxonomy_id
WHERE object_id = '88'

It uses an INNER JOIN that will take the taxonomy name from wp_term_taxonomy for the term_taxonomy_id ID.

As Anticom said, you should have a look at the JOIN in SQL, they would solve your problem and are easy to use.

Related Articles

mySQL Select from two tables and match result

I'd like to SELECT DISTINCT column1, column2 as t1 And i'd like to SELECT column3 FROM table2 WHERE column4 = "1" AND column3 = (matches)t1.column1 How should my query look like? SELECT DISTINCT column1, column2 FROM table1 as t1, column3 FROM t

SQL queries to select from two tables and compare with third

I am new to sql and trying to execute a query. I have created the following tables and they work properly. create table ACTOR ( actor_name varchar(30), gender varchar(8), date_of_birth date, primary key(actor_name) ); I keep getting stuck at on how t

Mysql selects from two tables

Can anybody tell me how to select data from two tables, without having to use join? Something like this: SELECT t1.*, t2.* FROM table1 t1, table2 t2 Clarification I have these two tables, that have the same fields. IE: table1 contains data from 2011

Query MySQL SELECT from a table and join the results with other tables

Newbie here. So I apologize in advance if it's so simple to solve my problem, but I couldn't find any solution. I have two tables MESSAGES and USERS: MESSAGES: |id|user_id|message|1st number|2nd number| USERS: |user_id|name| I'm trying to display a m

Select from two tables and order by datetime stamps

I have two MySQL tables similar to below: MESSAGES_IN messageID receivedDate message MESSAGES_OUT messageID sentDate message Basically, I want to select messages from both tables and order them by their respective dates. For example, if the data set

MySQL Selection from two tables sorted by date

Beginner here so please go easy on me :) So I have these two tables in my DB Reply Table +------------------------------------------------+ | message_id | client_id | message | date_posted | +------------------------------------------------+ Request

The Mysql operation between two tables and the output of wishes in one

I have two table amount_to_pay and paid_amount in amount_to_pay table data inserted as per center_id and university_id for which center for which university how much amount he has to pay and in paid_amount data inserted as which center for which univ

MySQL SELECT from two tables with COUNT

i have two tables as below: Table 1 "customer" with fields "Cust_id", "first_name", "last_name" (10 customers) Table 2 "cust_order" with fields "order_id", "cust_id", (26 orders) I need

MYSQL selecting from two tables but the second table does not always have a relationship with the first one

So I have two tables, one containing user info (Users), and the other containing info of which users not to show (Settings). So, I want to do a query that will show all the users in the users table except the ones listed in the settings. Thanks in ad

Mysql select with multiple tables and flexible output

select about three tables, where each tables have different fields. One may have the field "title", the other may not but have the field "location". Now i want to have a common output of these three tables, and each row is supposed to

MySQL Select FROM 3 tables AND put this into a PHP array

Sorry for bad english and bad title! I have the table "post" id title 1 test Thread 2 hello 3 just so have "tags" tagid tagname 1 test 2 russia 3 new site so have a post_tags tagid postid 1 1 2 1 3 1 I need an array from var_dump next

select from two tables and conditionally change a column

I have a list of Products upc | name | price | qty ---------------------------- 1 | apple | 1.00 | 3 2 | peach | 2.00 | 7 3 | melon | 1.75 | 2 and SaleProducts upc | price ------------ 2 | 1.90 I want to select from Products but also sale price from

MYSQl, select from two tables, count, with exception

If i use this query: SELECT map.x,map.y,users.username,Count(username) as count FROM map LEFT JOIN users ON (map.x=users.x AND map.y=users.y) WHERE map.y BETWEEN 0 AND 2 AND map.x BETWEEN 0 AND 2 GROUP BY map.x,map.y ORDER BY map.y DESC,map.x I get t

SELECTED from two tables based on the same identifier and grouped

I have two tables with different structure (table1 confirmed items, table2 items waiting for confirmation, each user may have more items in either table): table1 id (primary) | user_id | group_id | name | description | active_from | active_to and tab

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK