473,388 Members | 1,215 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

php/mysql help needed - if not exist, get proper value

I am trying to insert list of items from dev.test1 table, but I am struggling with logic ...

Face following problems:

- Before insert statements I would like to add "if not exists" - select content from dev.qa_postmetas
- f.URL which I am getting in second query is not coming from correct row in dev.test1 - If want to select f.URL where f.title = b.title

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO dev.qa_posts (type, categoryid, userid, created, title, content, tags)
  2. (SELECT  'Q_QUEUED', '1', '3', NOW(), f.title, f.img, f.tagsv
  3. FROM dev.test1 f)
  4. LIMIT 1;
  5.  
  6. INSERT INTO dev.qa_postmetas (postid, title, content) 
  7. (select MAX(b.postid) , 'qa_q_extra',f.URL
  8. from dev.qa_posts b
  9. left JOIN dev.test1 as f on b.postid = f.id)
  10. LIMIT 1 ;
Any assistance will be appreciated
Feb 28 '15 #1
1 1290
Dormilich
8,658 Expert Mod 8TB
1) why is there a LIMIT clause in an INSERT statement?

2)
Before insert statements I would like to add "if not exists"
make the table column that should not have duplicate entries UNIQUE. if you try to insert a duplicate value the DB will automatically reject the insert.

3)
If want to select f.URL where f.title = b.title
then why don’t you write that into the ON clause?
Mar 1 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Neal | last post by:
I have a simple survey with a drop down that lets users select different depts in our organization. Displaying the results to a different page works fine, but I would like to create another, same...
0
by: communityhooks | last post by:
Hi, I am having a particular problem. +-------------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra...
6
by: Mitesh | last post by:
How can I programattically retrieve MySQL server's port value through PHP?
1
by: kdvl | last post by:
I,m having a big trouble while getting a vlaue from table in mysql to a textarea. I can do that with a text field. But i dont know how to do it for a textarea. Please,send me the way as soon...
2
by: sandeepsandeep | last post by:
Hellow i am facing a problem in mysql query plesae solve it. I have a table Team_master with two field 1. team_id 2. team_name
1
by: CopZ | last post by:
have some doubts regarding the installation of the site $config - This sets the address of your database server. On most installations the database server is located on the same computer as...
1
by: kellen | last post by:
Maybe I can clarify, by showing a small, sample database (here, comma-delimited): MAKE, MODEL, PRICE, PRODUCT_LinE Ford, Escort A, $8999, Ford Escort Ford, Escort B, $9395, Ford Escort Ford,...
1
by: helraizer1 | last post by:
Hi folks, I am making a spreadsheet for a foreign exchange bureau, on the loading of the page it asks the operator to add the day's exchange rates. I have the following code in Excel VBA ...
5
by: scorpionbilli | last post by:
Hi, The local mysql server is running on my Macbook. I can access it through the console client: $ mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL...
3
by: raamay | last post by:
can anybody tell me why the following query returns null value. SELECT * FROM yjdf4_tbltenders AS a LEFT JOIN yjdf4_tblclass AS b ON a.cls = b.clid LEFT JOIN yjdf4_tblcategory AS c ON...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.